MATLAB: How to create an auto named variable

bad ideahorriblevariable assignment

Hello all, I am currently trying to crete a data base. How do I create automated variable names? i.e. Every time the program runs (when operator clicks add user), I want the variable name to be 'user_i' where i=usernumber+1 and usernumber is the previous value of i, to then save the variable with its name to the working directory in the form of save(filename,variables,'-append').
code:
%create user profile
usertemplate=[1:3];
usertemplate(1,1)=height;
usertemplate(1,2)=width;
usertemplate(1,3)=area;
if prog>=1
user1=usertemplate;
usernumber=usernumber+1;
save('database', 'user1','usernumber',-append);
else
userforID=usertemplate;
run('Similarity.m');
end
I would like user1 in the above code to be the auto named variable.
Thank you for any help you provide, and for helping me further my knowledge,
Ben

Best Answer

I agree with James - bad idea. Just make it a structure array and save the whole array
% Add a new user
allUsers(usernumber) = usertemplate;
But since you have only one field - the 1-by-3 template vector - you could just make it a 2D matrix
allUsers(end+1,:) = usertemplate;
save('database.mat', 'allUsers');