Effacer les filtres
Effacer les filtres

Store strings that are produced from a loop

2 vues (au cours des 30 derniers jours)
Kelly Kyriakou
Kelly Kyriakou le 12 Nov 2015
Commenté : Kelly Kyriakou le 13 Nov 2015
Hello, I want to store strings in a variable that have been provided by aloop. However, I do something wrong because it is stored only the porduced string from loop at my variable. Thi is my code
for allSS=1:size(scnames,1)
nameofsource2open = scnames{allSS,1};
for RPname2open = 1:4
readtraf=sprintf('traf_phasRP%d%s',RPname2open,nameofsource2open);
filename = [readtraf,'.xls']
if exist(filename, 'file') % File exist
counterscen2 = counterscen+1
filename2 = sprintf('trafscenRP%d%s',RPname2open,nameofsource2open)
alltraf = filename2
end
end
end
thank you in advance

Réponse acceptée

Walter Roberson
Walter Roberson le 13 Nov 2015
Before the loop have
alltraff = {};
And in the loop replace
alltraf = filename2
with
alltraf{end+1} = filename2;
  1 commentaire
Kelly Kyriakou
Kelly Kyriakou le 13 Nov 2015
Thank you very much. It works!

Connectez-vous pour commenter.

Plus de réponses (0)

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!

Translated by