load ascii data with multiple name
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
gugum gumbira
le 13 Avr 2016
Modifié(e) : Stephen23
le 15 Avr 2016
dear all,
I have some data with name ZA000060.TXT, ZA000120.TXT, ZA000180.TXT ..... at the same time I load data with :
for k=60:60:300
aa = sprintf('%d',k);
load (['ZA0000' aa '.TXT'],'AAA')
end
but there is error when load second data because the zero number.
unable to read file "ZA0000120.TXT"
Any help would be great,
Best regard,
5 commentaires
Réponse acceptée
Walter Roberson
le 13 Avr 2016
for k=60:60:300
filename = sprintf('ZA000%03d.TXT', k);
ZA{K} = load(filename);
end
3 commentaires
Guillaume
le 13 Avr 2016
To elaborate on Walter's answer. We suspect the problem is that you need a variable number of 0s before the actual number, depending on the actual number of digits.
This is what the '%03d' does in the formatstring of sprintf. It says prints the number as decimal (the d) with at least 3 digits (the 3) padded by zeros if necessary (the 0).
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Type Conversion 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!