Filter löschen
Filter löschen

String to Variable once more

3 Ansichten (letzte 30 Tage)
osminbas
osminbas am 12 Apr. 2012
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!

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 12 Apr. 2012
genvarname() was an incorrect solution. Please see Thomas's update, and Jan's answer.
Dynamic structure field names would be a better choice.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by