how to continue code in next line with comment between them

317 views (last 30 days)
mohammad m
mohammad m on 30 Apr 2017
Edited: John Hatrick on 24 May 2018
i have a long line code, that i want to specify each part of code by comment in above it. i use (...) at end of each part to continue code in next line.like this:
% line 1
a=b+c+f...
% line 2
+t+h+k;
but when i write comments between lines, matlab just calculate first line. now what should i do to write comment between break lines.

Accepted Answer

Stephen23
Stephen23 on 30 Apr 2017
Edited: Stephen23 on 18 Jan 2018
All you need is an ellipsis on each line which continues on to another line:
a = b+c+f...
... line 2
+t+h+k;
  4 Comments
John Hatrick
John Hatrick on 24 May 2018
Thanks!
Not quite as easy as ctrl-r, but I can work with it.

Sign in to comment.

More Answers (1)

Andrew Newell
Andrew Newell on 30 Apr 2017
Edited: Andrew Newell on 30 Apr 2017
You can have the comments beside each part instead:
a=b+c+f... % line 1
+t+h+k; % line 2
However, it is possible to over-comment code! Using meaningful names for variables is a way of making the code self-commenting.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!