Iterate through alphabetical names
Afficher commentaires plus anciens
Hello there,
maybe it's a dumb question, but how do I iterate through alphabetical names? Assuming I have matrices A to D, then how can I use those names in a loop?
My approach would be to create a string
names='ABCD'
and loop through those in a loop
for i=0:4
names(i)
end for
But how can I use this for example for the following operation?
boxplot(A(:))
If I simply use
names='ABCD';
for i=0:4
boxplot(name(i)(:))
end for
Then it doesn't work, of course. strcat does not do the job either.
I hope someone has an idea :)
Cheers
Réponse acceptée
Plus de réponses (2)
Marc
le 22 Mai 2014
4 commentaires
Star Strider
le 22 Mai 2014
If you already have a predefined variable name, simply use it:
for i=1:length(models)
fprintf('\t Open %s\n', models{i})
models(i)=xlsread(strcat(path,'\',eval(models(i)),'_PER.xlsx'));
end
However you will probably need to add dimensions to it to put the xlsread data into it:
for i=1:length(models)
fprintf('\t Open %s\n', models{i})
models(i,:,:)=xlsread(strcat(path,'\',eval(models(i)),'_PER.xlsx'));
end
Just guessing here, since I have no idea what ‘models’ is, what it contains, or that the various xls arrays are the same size (although I assume here that they are).
Marc
le 22 Mai 2014
Star Strider
le 22 Mai 2014
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!