Matlab call functions without parentheses

What's the correct name for a situation where Matlab-script calls a function but provides arguments without parentheses?

Example:

clear xx

      

Alternatively, I could use parentheses and pass a string with the name of the variable:

clear('xx')

      

How can I differentiate between both alternatives when searching along the path for a solution?

Bonus question: how can I put the contents of a variable in a call that does NOT use parentheses? In particular, a build-script using mcc with the dynamic -o filename parameter; a call to mcc with parentheses would also be acceptable, but I don't know like google, which is hence the question.

Thank!

+3


source to share


1 answer


When you call a function without parentheses, it is called strong syntax ... Here are three links to the relevant documentation:


Bonus answer

You cannot use a variable when using command syntax. From the docs:

When you call a function using command syntax, MATLAB passes the arguments as character vectors.

So it will work like this:

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

      



When called mcc

, as you suggest in the question, the tooltip shows that you can indeed use the function syntax, even though the documentation is fully shown using command syntax.

hint


Notes

The use of parentheses is standard practice in MATLAB, since you also cannot get output values ​​from a function when using command syntax.

Also from the third docs link above, you can see a post discouraging the use of command syntax when using MATLAB.

Note: While the unquoted syntax is convenient, in some cases it can be used incorrectly without calling MATLAB to generate an error.

+6


source







All Articles