how to continue code in next line with comment between them
조회 수: 142 (최근 30일)
이전 댓글 표시
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.
댓글 수: 1
France Lotto
2022년 10월 3일
편집: Steven Lord
2022년 10월 4일
This example shows how to continue a statement to the next line using ellipsis (...).
s = 1 - 1/2 + 1/3 - 1/4 + 1/5 ...
- 1/6 + 1/7 - 1/8 + 1/9;
Build a long character vector by concatenating shorter vectors together:
mytext = ['Accelerating the pace of ' ...
'engineering and science'];
The start and end quotation marks for a character vector must appear on the same line. For example, this code returns an error, because each line contains only one quotation mark:
mytext = 'Accelerating the pace of ...
engineering and science'
An ellipsis outside a quoted text is equivalent to a space. For example,
x = [1.23...
4.56];
is the same as
x = [1.23 4.56];
[SL Removed link]
채택된 답변
Stephen23
2017년 4월 30일
편집: Stephen23
2018년 1월 18일
a = b+c+f...
... line 2
+t+h+k;
댓글 수: 4
Steven Lord
2018년 5월 11일
And in fact this looks very similar to the example in the documentation for ellipsis. See the row for ... (Dot dot dot or ellipsis) in the "Special Characters" table on this documentation page, particularly the second half of the Examples column. [I see Stephen already linked to that documentation page, but didn't explicitly reference that particular section of that table.]
John Hatrick
2018년 5월 24일
편집: John Hatrick
2018년 5월 24일
Thanks!
Not quite as easy as ctrl-r, but I can work with it.
추가 답변 (1개)
Andrew Newell
2017년 4월 30일
편집: Andrew Newell
2017년 4월 30일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!