MATLAB: Using variables whose names are stored in another array

arraywho

Hi
I have created a list of variables in the workspace using 'who' and now I would like to use the variable names stored to conduct operation on them but I am having trouble access the. For example I have used command a=who; or a= whos; and now a has names of about 400 variables in the workspace, so then I want to b able to do operations on the variables by using values stored in a. e.g. a(1,1).names = 'ABC' and ABC is an array of 10 values and I want to operate on those values but I can't seem to access the values of ABC using a… please help

Best Answer

As per Stephen's comment, you're on your way to more trouble and you really need to rethink the way you're storing your data. Your 400 different vectors should have been stored in a matrix or table if all the same size, or a cell array otherwise. Either way, one line of fast, easy to debug, code would be all that's needed to add that single value.
As it is, it is still possible using eval and its friends ( evalin and assignin), but speed, ease of debugging, syntax highlighting all go out of the window:
%this code assumes it's run as a script.
for var = who'
tempval = eval(var{1}); %get variable value
tempval = [tempval, rand]; %add one value, replace rand by whatever you want
assignin('base', var{1}, tempval);
end