필터 지우기
필터 지우기

String to Variable once more

조회 수: 3 (최근 30일)
osminbas
osminbas 2012년 4월 12일
Hello,
I am having hard time following a generic code for this. So I will put my own code in and see if anyone can help me: ...
Columns={'A';'B';'C';'D';'E';'F';'G';'H';'I';'J';'K';'L';'M';'N'};
Rows={'2';'31';'61';'91';'121';'151';'181';'211'};
Labels={'0';'01';'02';'04';'08';'16';'24';'36';'50';'625';'75';'875';'1';'1125'};
for i=1:14;
Var1=strcat('Rand',Labels(i,1));
Var2=strcat('Delta',Labels(i,1));
C1=strcat(Columns(i,1),Rows(j,1));
if exist(Var1{1,1},'var')==1 && exist(Var2{1,1},'var')==1
xlswrite(filePattern4,genvarname(Var1{1,1}),'Sheet1',C1{1,1});
xlswrite(filePattern4,genvarname(Var2{1,1}),'Sheet2',C1{1,1});
end
end
The variables Rand0, Rand01, etc. are defined at the beginning of the code but they are case dependent so some of them are not always there. That is why I use exist. I thought genvarname would work to convert string into variable but it didn't. Could anyone help with this? Thank you!

채택된 답변

Walter Roberson
Walter Roberson 2012년 4월 12일
genvarname() was an incorrect solution. Please see Thomas's update, and Jan's answer.
Dynamic structure field names would be a better choice.
  댓글 수: 1
osminbas
osminbas 2012년 4월 12일
OK, got it! Thanks!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by