This enhancement has been incorporated in Release 2006b (R2006b). For previous product releases, read below for any possible workarounds:

The EVALIN function allows you to evaluate commands in two specfied workspaces: 'base' (MATLAB's base workspace), and 'caller' (the workspace where the function was called from). In the case where the function was called from the base workspace, the two workspaces are the same. You will need to create a string that will evaluate as the proper MATLAB expression, in order to perform the assignment.

Example using EVALIN:

function myfcn(varname)

for i = 1:size(varname,1)

if iscellstr(varname),

evalin('base',[varname{i} ' = 'mat2str(i) ';'])

elseif ischar(varname)

evalin('base',[deblank(varname(i,:)) ' = 'mat2str(i) ';'])

end

end

The ASSIGNIN function assigns values to variables in the same specified workspaces. This allows you to avoid the string conversion which is necessary with EVALIN.

Example using ASSIGNIN:

function myfcn(varname)

for i = 1:size(varname,1)

if iscellstr(varname),

assignin('base',varname{i},i)

elseif ischar(varname)

assignin('base',deblank(varname(i,:)),i)

end

end

## Best Answer