String to Variable once more
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Walter Roberson
le 12 Avr 2012
genvarname() was an incorrect solution. Please see Thomas's update, and Jan's answer.
Dynamic structure field names would be a better choice.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!