Reading data from different data files
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
Hello, I need some help importing data files. I'm running some simulations, which result in simple files with 3 columns. Nothing new so far. However, I do not have the same amount of data files for each variable. To make things clear: Let's say I have to following data files: Fx_1_1_1 Fx_1_1_2 Fx_1_1_3 Fx_1_1_4 Fx_1_1_5 Fx_1_1_6 Fx_1_1_7 Fx_1_1_8 Fx_1_2_1 Fx_1_2_2 Fx_1_2_3 Fx_1_2_4 Fx_1_2_5 Fx_2_1_1 Fx_2_1_2 Fx_2_1_3 Fx_2_1_4 Fx_2_1_5 Fx_2_1_6 Fx_2_1_7 Fx_2_2_1 Fx_2_2_2 Fx_2_2_3 Fx_2_2_4 Fx_2_2_5 Fx_2_2_6
I'm using (as long as i had the same amount of data files for each place)
filepath = 'C:\...\...\...\Fx_';
for a=1:2
for b=1:2
for c=1:8
filename = strcat(strcat(strcat(strcat(strcat(filepath,int2str(a)),'_'),int2str(b)),'_'),int2str(c),'');
filedata = load(filename);
blabla doing something with the files;
end
end
end
Now I don't know how to change these lines so that I can import all files and do the analysis I need. Whenever I run the code and I don't have, for example Fx_1_2_6 it returns an error. Does anyone know how I can avoid this?
1 comentario
Vishal Rane
el 30 de Nov. de 2012
Editada: Vishal Rane
el 30 de Nov. de 2012
What do the three numbers in the file name represent ?
Also you can reduce the file name construction command to this :
filename = [ filepath, int2str(a), '_', int2str(b), '_', intstr(c)];
Respuestas (1)
dpb
el 30 de Nov. de 2012
Use dir() w/ appropriate wild card for the subset of names desired then process the resulting list...
d=dir('Fx_1_*');
for f={d.name}
x=load(f);
% process
end
You can enclose the above in the req'd loops to build the wild card string as needed...
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!