function - assign values to variable names in Matlab -
is there way assign values variable names both supplied user?
i thought of along these lines:
function varargout=my_fun(varargin) i=1:2:nargin eval('varargin{i}=varargin{i+1}') end >> my_fun('a',1,'b',2) >> 1 >> b 2
but doesn't work.
you using assignin
, recommend not use such solution. violates common expectations of variable scope. besides this, assignin
, eval
2 of best option confuse matlab editor, results in many useless recommendations , warnings.
if need such solution:
assignin('caller',varargin{i},varargin{i+1})
assign caller work space.
Comments
Post a Comment