how can I insert comments into a multiline array creation?
5 次查看(过去 30 天)
显示 更早的评论
This works
>> p = [...
%%%BEGIN ENTRIES %%%
'a1;', ...
'b;', ...
'c;'
]
p =
a1;b;c;
but commenting out the 'b' line doesn't
p = [...
%%%BEGIN ENTRIES %%%
'a1;', ...
% 'b;', ...
'c;'
]
Dimensions of matrices being concatenated are not consistent.
0 个评论
采纳的回答
Walter Roberson
2017-12-27
p = [...
%%%BEGIN ENTRIES %%%
'a1;', ...
... % 'b;', ...
'c;'
]
Note: ... itself acts as a comment operator for the rest of the line, so you could get away with
p = [...
%%%BEGIN ENTRIES %%%
'a1;', ...
... 'b;', ...
'c;'
]
However this would tend to confuse people as it is not common to use this and readers might not pick up on the fact the rest of the line was a comment.
2 个评论
Walter Roberson
2017-12-27
... has the side effect of also ignoring the rest of the line, but it has the primary effect of continuing the previous statement.
The portion of the 'b;' line before the % is not commented out, so
p = ['a1;', ...
% 'b;', ...
'c;']
is the same as
p = ['a1;', ...
'c;']
which is not the same as
p = ['a1;', ...
'c;']
The
p = ['a1;', ...
'c;']
version should be looked at as if it were
p = ['a1;', ...
[]
'c;']
which would be the same as
p = ['a1;', []
'c;']
The default within [] is that lines that do not end in continuation are treated as if they had ; at the end of them, so this is
p = ['a1;', [];
'c;']
which is
p = ['a1;';
'c;']
and that fails because the number of columns is not equal.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!