MATLAB Answers

Run a script in each subfolders and extract results for each subfolders in another folder

83 views (last 30 days)
EMILIO BASTA
EMILIO BASTA on 26 Feb 2021
Answered: Jan on 27 Feb 2021
I have a 'folder' which contains several subfolders for each sea wave height and period :
-subfolder(1:n) : 'Hs(0.25:0.5:5.25) Tp(2.5:1:9.5)'
example: subfolder(1) : 'Hs(0:25) Tp(2.5)'
.....
subfolder(4) : 'Hs(0.75) Tp(2.5)'
.....
subfolder(7): 'Hs(1.25) Tp(3.5)'
subfolder(8) : 'Hs(1.25) Tp(4.5)'
....
subfolder(11) : 'Hs(1.25) Tp(9.5)'
....
subfolder(end): 'Hs(5.25) Tp(9.5)'
I have several subfolders which are the combination between different Hs and different Tp. In each subfolder there is a 'file.mat'. I have to run the same matlab code in each subfolder to extract results from 'file.mat' and save them in another folder.
I would like to get in each subfolder through a code which can distinguish the several Hs and Tp cases (double for cycle) and run a code in order to extract results from 'file.mat' and extrapolate data in another folder.
Please help, I am a beginner.

Accepted Answer

Jan
Jan on 27 Feb 2021
FileList = dir(fullfile(Folder, '**', 'file.mat'));
for iFile = 1:numel(FileList)
SubFolder = FileList(iFile).folder;
Data = load(fullfile(Folder, FileList(iFile).name));
... Run your code with this data
end

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!