MATLAB: Using a variable to rename other variables

variable

Ok, this is a simple problem, I guess, but I couldn't find an answer. I have one variable with the name of the file (say, filename='Al_10_X'), and I have ten variables with the data I want to use. I want to rename the ten variables using the filename. I've tried-
strcat (filename,'_m1y')=E_m1_y(:,:,1,1);
eval(sprintf('%i_m1x)=E_m1_x(:,:,1,1);' ,filename))
and a combination of both. Any ideas?

Best Answer

Creatinting such ‘dynamic variables’ is not considered to be good programming practice. They are difficult to work with.
Creating descriptive variable names is good practice. I would create a single array (numeric or cell array) for each file and just keep track of it. That would follow directly from the way MATLAB reads files, and would eliminate the possibility of dynamic variables.
Related Question