EDIT
After I answered this, a better strategy has been found: Just use nargin
; see @k-messaoudi's answer.
For inline functions:
According to inline
's help:
INLINE(EXPR) constructs an inline function object from the MATLAB expression contained in the string EXPR. The input arguments are automatically determined by searching EXPR for variable names (see SYMVAR).
Therefore: call symvar
and see how many elements it returns:
>> f = inline('x + y');
>> g = inline('x');
>> numel(symvar(f))
ans =
2
>> numel(symvar(g))
ans =
1
For anonymous functions:
First use functions
to get information about the anonymous function:
>> f = @(x,y,z) x+y+z;
>> info = functions(f)
info =
function: '@(x,y,z)x+y+z'
type: 'anonymous'
file: ''
workspace: {[1x1 struct]}
Now, again use symvar
on info.function
:
>> numel(symvar(info.function))
ans =
3