change name of variable completely in a loop

조회 수: 2 (최근 30일)
chess
chess 2014년 8월 17일
댓글: chess 2014년 8월 17일
I have a question.I wonder is there anyway in Matlab to change the name of variable to completely different thing in a for loop? Meaning that I would like name of first variable to be variable211, second variable is variable232 and third variable is variable345.
I am aware of something like:
for i=1:10
A(i)=i^2 % This creates A(1),A(2)......A(10)
I know I can use cell array but that one still gives something like array like A{1}, A{2}.I am looking completely different name like I explained above.
  댓글 수: 2
Adam
Adam 2014년 8월 17일
How would you expect to be able to access all these variables afterwards if they were able to have transient names? That is exactly what an array is for to have one variable name and lots of results.
chess
chess 2014년 8월 17일
like normal variables ,I run the for loop and all of those variables are copied in the workspace.It is not a good opinion but I just want to do it for specific task to make the name of variables more meaningful.

댓글을 달려면 로그인하십시오.

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 8월 17일
  댓글 수: 2
chess
chess 2014년 8월 17일
I do not know why everyone recommends this link. However this is not what I want. I just want to know is it possible to change name of variable or image from one iteration to next to a custom name like for i=1 it is variable211 for i=2 it is variable235
Azzi Abdelmalek
Azzi Abdelmalek 2014년 8월 17일
Because the link explains how to create a variable, variable211
i=1
eval(sprintf('varaible%d=%d',211,i))

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by