Assigning data from a variable output argument list

Go To StackoverFlow.com

2

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.

2012-04-04 17:00
by Jacob


1

It looks like this should work:

out = cell(size(inp));
[out{:}] = ndgrid(inp{:});
2012-04-04 17:24
by yuk
Ads