Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Handling of multiple files/folders

Asked by 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

0 Comments

Andreas

Products

No products are associated with this question.

1 Answer

Answer by Rene on 30 Mar 2011
Accepted answer

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

Andreas on 1 Apr 2011

Thank you for your help. It got me on the right track and I finally managed to solve my problem.

/Andreas

Jan Simon 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 on 18 Apr 2011

Corrected the missing quote.

@Jan Simon:
Thanks for the comments, good to learn about FULLFILE.

Rene

Contact us