当您调用不带括号的函数时,它被称为命令语法.以下是相关文档的三个链接:
奖金回答
使用命令语法时,不能使用变量.来自文档:
When calling a function using command syntax, MATLAB passes the arguments as character vectors.
所以它会像这样工作:
abc = zeros(10); % Some matrix called abc
mystring = 'abc' % A string containing the variable name
% Option 1:
clear('abc') % Clears the variable abc
% Option 2:
clear abc % As per above docs quote, interpreted as clear('abc')
% Option 3:
clear mystring % As per option 2, interpreted as clear('mystring') so doesn't work
% Option 4:
clear(mystring) % Interpreted as clear('abc') so works as expected
当您在问题中建议调用mcc时,工具提示显示您实际上可以使用函数语法,尽管使用命令语法完全显示documentation.
笔记
使用括号是MATLAB中的标准做法,因为在使用命令语法时也无法从函数中获取输出值.
同样从上面的第3个文档链接中,您可以看到一条消息,在使用MATLAB时不鼓励使用命令语法.
Caution: While the unquoted command syntax is convenient, in some cases it can be used incorrectly without causing MATLAB to generate an error.