MATLAB Answers


Handling of multiple files/folders

Asked by Andreas
on 30 Mar 2011


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?



Log in to comment.


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:

for i=1:10

will load files


Hope that helps



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


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

Corrected the missing quote.

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

Log in to comment.

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

MATLAB Academy

New to MATLAB?

Learn MATLAB today!