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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -