Handling of multiple files/folders

1 view (last 30 days)
Andreas
Andreas on 30 Mar 2011
Hi,
I'm currently if the process of postprocessing data from 100 CFD simulations for the flow over a flat plate. Each simulation produce 20 datafiles (.csv) that I require to calculate the boundary layer thickness along the plate, and I've created a program that import the 20 files from one simulation (using importfile) and then calculates the BL thickness from the data. The problem is that it can only handle data from one simulation at a time and I'm not to keen on running the program 100 times, changing file locations between each run manually.
The file structure I have consists of 10 folders (Bump1, ..., Bump10) with 10 subfolders each (Reynoldsnmb1, ..., Reynoldsnmb10) and then in each subfolder i have the 20 csv files.
What I want the program to do first is go into /Bump1/Reynoldsnmb1/, import the data and do all the calculations. Move on to Reynoldsnmb2 and do all calculations etc. and then do this process for Bump1-10.
Do you have any suggestions on how this could be done?
/Andreas

Accepted Answer

Rene
Rene on 30 Mar 2011
The way I usually do this is to use sprintf() to create the string of the filename. Eg:
data=cell(10,1);
for i=1:10
dirname=sprintf('run%02d/subdir',i);
fname1=sprintf('%s/filename1.dat',dirname);
data{i}=load(fname);
end
will load files
run01/subdir/filename1.dat
run02/subdir/filename1.dat
...
run10/subdir/filename1.dat
Hope that helps
Rene
  3 Comments
Jan
Jan on 1 Apr 2011
Using FULLFILE instead of hardcoded file separators in the string (use '\\' on PC, not '\'!) has some advantages: automatically consideration of OS styles and tolerance for "C:\" and "C:\folder". Therefore FULLFILE is a good programming practice.
@Rene: There is a missing quote ind the "fname1=..." line. Your example uses pre-allocation, catchs the output of LOAD in a variable, and avoid EVAL - fine! +1 vote
Rene
Rene on 18 Apr 2011
Corrected the missing quote.
@Jan Simon:
Thanks for the comments, good to learn about FULLFILE.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!