In Matlab, I want to select by name and loop through some elements in the workspace, let's say for example these matrixes:
mymatrix1=ones(2);
mymatrix2=zeros(2);
mymatrix3=magic(2);
I can select them using who
:
list_of_mymatrixes=who('mymatrix*');
to do some operation, for example write them to respective files:
for i=1:length(list_of_mymatrixes)
x=strcat("my_matrix_number_",string(i));
dlmwrite(x,list_of_mymatrixes(i,1));
end
but they are stored as just the variable name. open('my_matrix_number_1')
shows m,y,m,a,t,r,i,x,1
So, which is the way to loop through these elements so that they are recognized as matrixes instead of strings (their names)?