The command looks nicer when written as:
evalin('base', 'save(arNames{index(iii,1),:}, arNames{index(iii,1),:})')
This will work if arName and iii is defined in the base-workspace as well as the variable with the name called arNames{index(iii,1),:}. But I assume, these variables are defined in the local workspace. Therefore I stringly recommend not to use evalin for such spoofing tricks.
[EDITED]: To create the command string, when arNames, index and iii are defined locally:
name = arNames{index(iii)};
evalin('base', sprintf('save(''%s'', ''%s'')', name, name));
As usual for eval and its evil brothers, enclose this command in a try, catch block and verify that name is a valid symbol, e.g. by:
if strcmp(genvarname(name), name) == 0
error('author:toolbox:badSymbol', ...
'Bad symbol: [%s]', name);
end
This will reduce the risk of a name like "system('format D:')". I do not think, that you use such names. But bugs happen. And by definition bugs are unexpected and have unexpected results. Then it is surely a wise idea to let them not use EVAL/EVALIN as a gun to shoot up your computer. However, avoid EVAL/EVALIN would even be smarter and it is always possible.
Best Answer