I get Error: Invalid expression. Check for missing or extra characters. when commenting out lines in a multi-line statement
9 次查看(过去 30 天)
显示 更早的评论
It seems you can't comment-out entire lines in MATLAB within a multi-line statement. Or am I doing it wrong.
A few examples below.
1. Expressions
y = ...
1 + ...
2 + ...
3
Returns:
y =
6
y = ...
1 + ...
%2 + ...
3
Raises:
%2 + ...
↑
Error: Invalid expression. Check for missing or extra characters.
2. Structure definitions
s = struct(...
'A',1,...
'B',2,...
'C',3....
)
Returns:
s =
struct with fields:
A: 1
B: 2
C: 3
struct(...
'A',1,...
% 'B',2,...
'C',3...
)
Raises:
% 'B',2,...
↑
Error: Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched
delimiters.
Even if I use the Comment tool (
) in the MATLAB editor it causes these errors.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/351548/image.png)
This is such a basic task! What am I doing wrong?
0 个评论
回答(2 个)
madhan ravi
2020-8-25
You're right.
2 个评论
madhan ravi
2020-8-25
编辑:madhan ravi
2020-8-25
It expects anything (in a MATLAB sense) other than a comment.
Bill Tubbs
2020-8-25
2 个评论
madhan ravi
2020-8-25
It is the same as
y = ...
1 + ...
... 2 + ...
3
Which does exactly as the document says that I linked in my answer.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!