As suggested above: The best idea is not to create the variables in this way at all. Hiding an index in the name of the variable is a bad idea.
But if you have these names already and cannot change the code, which creates them - what's wrong with:
? Is the number of variables unknown? Do the variables come from an imported MAT file? Then this would help:
Data = load('File.mat');
C = struct2cell(Data);
M = cat(2, C{:});
Nevertheless, the main goal is to avoid the creation of such variables from the beginning.
3 Comments
Stephen Cobeldick (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/346695-how-to-save-variables-to-an-array-using-a-for-loop#comment_465228
Debby Amaya (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/346695-how-to-save-variables-to-an-array-using-a-for-loop#comment_465485
Stephen Cobeldick (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/346695-how-to-save-variables-to-an-array-using-a-for-loop#comment_465504
Sign in to comment.