Well, thanks to all partisipated in discussion. Summing up, it seems the problem has no general solution, because MatLab itself estimates the number of desired outputs before the function call to use inside it. Three cases can be pointed out though:
1) The funcrion doesn't have varargout
in definition, thus nOut=nargout(@fcn)
returns positive number.
Then nOut
is an actual number of outputs and we can use a cell array and a column list trick.
X=cell(1,nOut);
[X{:}]=fcn(inputs);
2) The funcrion has varargout
in definition, thus nOut=nargout(@fcn)
returns negative number. However some correlation with inputs can be found (like length(varargin)=length(varargout)
).
Then we can calculate the resulting nOut
from inputs
and perform the above column list trick.
3) You know the fcn
developer.
Ask him fot assistance. For example to make the function's output to be a cell array.