String to Variable once more
2 ビュー (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
採用された回答
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!