Consider a function varargout = foo(varargin)
. I know how to format a comma separated list so we can generate varargin
automatically. E.g. [x y z] = ndgrid(-1:1,-1:1,-1:1)
is equivalent to:
inp = repmat({-1:1},[1 3]);
[x y z] = ndgrid(inp{:});
My question is: how do I obtain the output (x,y,z
in the example) automatically? I.e.,
out = ndgrid(inp{:});
PS: I would like to avoid using eval
.
It looks like this should work:
out = cell(size(inp));
[out{:}] = ndgrid(inp{:});