How to write an ''if''condition to determine what variable are in a function ?
Show older comments
example sometime I will use : f=@(x,t) 8x+3t
or i will use
f=@(x) cos(x)
now I want an if function thats looks like this :
if f depends only on x
do gjgjgjgjg
elseif f depends on x and t
do jnfundinb
else
do kgnmpofgn
Accepted Answer
More Answers (1)
If the only thing that actually matters is the number of input arguments (and not their specific names), then you can trivially use nargin like this:
fun = @(...)...;
switch nargin(fun)
case 0
...
case 1
...
...
end
This will be more efficient than converting the entire function to string.
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!