Why does a commented out line generate an error
5 次查看(过去 30 天)
显示 更早的评论
The following code throws an error
CellArray = { ...
'X' ...
% ,'X' ...
,'X' ...
};
The error is:
Dimensions of matrices being concatenated are not consistent.
If I erase the commented out line, there is no error. So my question is: why isn't commenting out a line equivalent to erasing it.
0 个评论
采纳的回答
Walter Roberson
2018-6-8
编辑:Walter Roberson
2018-6-8
Using ... is equivalent to bringing the next line up to the end of the current line. So that code is equivalent to
CellArray = { 'X' % ,'X' ...
,'X' };
The last last of those lines is not brought up to the previous one because the ... itself on the line before it has been commented out.
You need to use
CellArray = { ...
'X' ...
... % ,'X' ...
,'X' ...
};
Or, since ... itself acts to comment out the rest of the line,
CellArray = { ...
'X' ...
... ,'X' ...
,'X' ...
};
2 个评论
Walter Roberson
2018-6-8
It is by definition.
"Three or more periods at the end of a line continues the current command on the next line. If three or more periods occur before the end of a line, then MATLAB ignores the rest of the line and continues to the next line. This effectively makes a comment out of anything on the current line that follows the three periods."
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!