Running files in folders in loop.

6 views (last 30 days)
Yashvardhan Bhati
Yashvardhan Bhati on 20 Oct 2022
Answered: Benjamin Kraus on 21 Oct 2022
I have multiple folders numbered in sequence 9D-15D and inside each folder is ther is another folder numbered in sequence S_1 to S_15 and inside each folder there are files which i would read using the matlab code which i have and save data to that folder named with S_$ and do that for all the folders present and in $D folders. I can do that in other coding language but not sure how to preceed in matlab. So if you guide or tell me where to look for it would be very helpful.
9D
S_1
%Files to read using matlab code and save data
S_2
.
.
.
S_15
10D
S_1
.
.

Answers (1)

Benjamin Kraus
Benjamin Kraus on 21 Oct 2022
You can use the dir command to get a list of the files/folders.
d = dir('**');
Once you have the list, you can loop through them to read your data and write your desired output.
You may also find the fullfile, fileparts, filesep, and exist helper functions handy when processing files like this.
You didn't specify the format of the data in the files, or the desired output format, so if you need more assitance with actually reading and writing the files, you will need to provide more specifics.

Categories

Find more on File Operations in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!