MATLAB: Assign value to dynamically named variable in loop

bad ideaMATLABnamevariable

I name variables dynamically in loop within a function:
for l=1:max(uv)
label=cell(total_images,4);
tempname=strcat('label',num2str(l));
renvar('label', tempname());
end
so, I get variables label1, label2, label3,… I must assign values to them afterwards but since I do not know how many variables will be created because of max(uv) I have to obtain variable names on the left dynamically e.g. labelX{1,1}=imgtemp{1,1}; X should be dynamically assigned. I tried with "assignin" and "eval" without success.
any help?

Best Answer

Do not do this. This forum is filled with scores of posts discussing why this is a bad idea.
Instead, use cell arrays, and assign your variables like this
label{i}
Then, those can be use pretty much exactly how you want to use your dynamically named variables.