what does these three dots mean in this equation...

diff_im = diff_im + ...
delta_t*(...
(1/(dy^2))*cN.*nablaN + (1/(dy^2))*cS.*nablaS + ...
(1/(dx^2))*cW.*nablaW + (1/(dx^2))*cE.*nablaE + ...
(1/(dd^2))*cNE.*nablaNE + (1/(dd^2))*cSE.*nablaSE + ...
(1/(dd^2))*cSW.*nablaSW + (1/(dd^2))*cNW.*nablaNW );

 채택된 답변

Walter Roberson
Walter Roberson 2012년 1월 8일

0 개 추천

The three dots mean line continuation. MATLAB expressions normally end at the end of the line unless they are specifically continued (exception: within the [] list building operator.)

댓글 수: 8

The documented meaning of the three dots is the line continuation. However, I saw a script using the token as a comment opening character at the same time. Evidently, all the rest of the line behind the dots is ignored by the parser and can be used for comments.
My question: Is this a well-defined, documented, officially supported feature or is it just a deprecated side-effect of the token?
Stephen23
Stephen23 2017년 1월 31일
편집: Stephen23 2017년 1월 31일
This clearly recommends using the ellipses for commenting out:
"To comment out part of a statement that spans multiple lines, use an ellipsis (...) instead of a percent sign."
Yes, this is a documented feature.
"Three or more periods before the end of a line cause the MATLAB® software to ignore the remaining text on the current line and continue the function on the next line. This effectively makes a comment out of anything on the current line that follows the three periods"
Jan
Jan 2017년 1월 31일
편집: Jan 2017년 1월 31일
@Stephen: Using the ellipsis in such cases avoids the ambiguity for the line breaks:
header = [1 ...
... 2
3]
This is [1, 3], but:
header = [1 ...
% 2
3]
is [1; 3], a column vector, because the implicite line break is taken as separator of lines. This even happens, if comma is used as separator:
header = [1, ...
% 2
3]
replies [1; 3]. Brrr, not intuitive.
You see, this is important. Please post this as additional answer.
Certainly the lack of consistency is not intuitive, but
header = [1 ...
... 2
3]
producing [1, 3] is not overly intuitive either!
I often wanted an option like C++ /* */ commenting in Matlab, but now that I see it it is so ghastly I don't think I would ever dream of doing such a thing in code. Even if it is documented, using the line break operator as a comment tool is horrible!
Historically, /**/ is C style comments, C++ recommended style is // commenting to end of line (but /**/ is supported for backwards compatibility.)
Jan
Jan 2017년 2월 1일
편집: Jan 2017년 2월 1일
@Adam:
using the line break operator as a comment tool is horrible!
Do you mean the "line continuation operator" or that the linebreak in the text is interpreted as row break in the matrix? I agree with both.
Adam
Adam 2017년 2월 1일
Well, I was meaning the line continuation operator. I have been known to have functions in C++ where I comment out one argument temporarily from the middle of the list (either formatted with the full function signature on one line or, as I often do in Matlab, with one argument per line), but at least there it has more of a look of being commented out, being surrounded by operators that would not otherwise be anywhere near.
The idea of having 1 ... on one line and ... 2 on the next line meaning that only the 1 is actually part of the code is not programmer-friendly. Having just tried it for the first time though I notice the '2' does at least turn green to show it is commented out.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jan
Jan 2017년 2월 1일
편집: Jan 2017년 2월 1일

1 개 추천

I summarize the important comments of Stephen Cobeldick and Steven Lord above to make this more prominent:
Beside the line continuation, the ellipsis '...' starts a comment also:
To comment out part of a statement that spans multiple lines, use an ellipsis (...)
instead of a percent sign.
Using a % is interpreted as line break and therefore as an implicit row break of the data:
header = [1 ...
... 2 % line break commented away
3]
>> [1, 3]
header = [1 ...
% 2 % line break interpreted as row break
3]
>> [1; 3]
header = [1, ...
% 2
3]
>> [1; 3] % ???
header = [1; ...
... 2
3]
>> [1; 3] % As intented obviously
Only the last version looks intuitive for me. I'm still convinced that it was a bad design idea to allow spaces as column-separators and linebreaks as row-separators because this leads to ambiguities.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

2012년 1월 8일

댓글:

2017년 2월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by