rename a variable

조회 수: 5 (최근 30일)
Baba
Baba 2012년 3월 5일
in my workspace i have an array that is named 'data' and I have a name field with some filename = 'filename'
I would like to rename the array called data to the name that is stored in the filename name variable.
simply doing filename = data; renames data to filename not the actual name that filename holds.

채택된 답변

Matt Tearle
Matt Tearle 2012년 3월 5일
Let me see if I interpret the question correctly: you have
filename = 'bob';
data = [1,2,3];
And you want to rename data to bob (the contents of filename)?
Firstly, be careful doing things like this. It makes it very hard to track names. But, if you must...
str = [filename,'= data;'];
eval(str);
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 3월 5일
"if you must" then you probably have not written your program in a good way.
Baba, use dynamic structure field names of a single structure variable that will contain all of the data.

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

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2012년 3월 5일
Similar to FAQ

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by