Reading data from different data files
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
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
Vishal Rane
2012년 11월 30일
편집: Vishal Rane
2012년 11월 30일
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)];
답변 (1개)
dpb
2012년 11월 30일
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...
댓글 수: 0
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!