"So in order to generalize, is there any possible way to know in advance that the expression is going to send one or two output arguments?"
How would you then call those functions with one, and those with two outputs? It would be possible by allocating a cell array and using acomma-separated list, or by using some incomprehensibleeval-based code, but really either of those is going to ugly spaghetti code.
A much simpler solution would be to use atry andcatch:
C = {@(x,y)min(x), @(x,y)min(x)+min(y), @(x,y) min(x+min(y))};
x = 4;
y = 3;
for k = 1:numel(C)
try
[out,idx] = C{k}(x,y)
catch
out = C{k}(x,y)
end
end
which works without error, and does not use uglyeval. Or you with Mfiles could usenargout, e.g.:
Best Answer