How do I create an auto named variable?
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
James Tursa
2015년 2월 17일
편집: James Tursa
2015년 2월 17일
2 개 추천
Before you do this you should read this link:
Using variable names like this can be very cumbersome in downstream code. If you do decide to go this route, I fully expect another Question posted by you in the future along the lines of "How do I efficiently access all of the variables named user1, user2, etc in my database?"
카테고리
도움말 센터 및 File Exchange에서 Database Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!