load ascii data with multiple name

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 comentarios

Stephen23
Stephen23 el 13 de Abr. de 2016
Editada: Stephen23 el 15 de Abr. de 2016
@gugum gumbira : Why do you think that " error when load second data because the zero number" ?
You don't give us the complete error message, and there is no reason why a zero digit in a filename would cause any error. Please show us the complete error message.
Also note that it would be much better to load the data into one cell array:
V = 60:60:300;
C = cell(size(V));
for k = 1:numel(V)
filename = sprintf('ZA000%03d.TXT', V(k));
C{k} = load(filename);
end
Do NOT load the variables individually, this will make your code much more complicated.
Edit: simplify example code.
gugum gumbira
gugum gumbira el 13 de Abr. de 2016
Thanks for quick reply :) with this syntax for k=60:60:300 aa = sprintf('%d',k); load (['ZA0000' aa '.TXT'],'AAA') end
I got this error
Error using load Unable to read file ZA0000120.TXT: Tidak ada berkas atau direktori seperti itu. the right load is "ZA000120.TXT" not "ZA0000120.TXT"
and using your syntax I got this error
"Assignment between unlike types is not allowed." thanks for your help before :)
Stephen23
Stephen23 el 14 de Abr. de 2016
Editada: Stephen23 el 14 de Abr. de 2016
@gugum gumbira: I corrected and tested my example.
gugum gumbira
gugum gumbira el 15 de Abr. de 2016
I got some errors with your syntax. would you please give full explanation about load the data into one variable
thanks
Stephen23
Stephen23 el 15 de Abr. de 2016
Editada: Stephen23 el 15 de Abr. de 2016
You didn't replace the ellipses with the filename. Specify the filename and it will work.

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 13 de Abr. de 2016
for k=60:60:300
filename = sprintf('ZA000%03d.TXT', k);
ZA{K} = load(filename);
end

3 comentarios

gugum gumbira
gugum gumbira el 13 de Abr. de 2016
I got nothing with this script :( I hope the data would be load for each .TXT data
Thanks
Guillaume
Guillaume el 13 de Abr. de 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).
gugum gumbira
gugum gumbira el 14 de Abr. de 2016
Thanks alot :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 13 de Abr. de 2016

Editada:

el 15 de Abr. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by