Use a variable with a file extenstion to load files

1 visualización (últimos 30 días)
David
David el 14 de Ag. de 2014
Comentada: David el 14 de Ag. de 2014
Hi,
I Have 51 files in their own directory all of .out extention created by a seperate program, all numbered 0 to 50.
ie
0.out
1.out
2.out
and so on til 50.out.
I need to load each file 1 by one to do calculations upon them within a for loop. How would I do this using the count variable to load the file, if the directory is set beforehand?
i.e.
%set directiory
cd(......)
%for loop
For count = 0:50,
data = count.out *<-----this line*
.....
Many thanks!

Respuesta aceptada

Chad Greene
Chad Greene el 14 de Ag. de 2014
You can use sprintf or num2str. num2str is easier to use, but sprintf gives many more options including leading zeros.
  2 comentarios
Chad Greene
Chad Greene el 14 de Ag. de 2014
data = load([num2str(count),'.out']);
David
David el 14 de Ag. de 2014
thanks:)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by