How to run a matlab code for all folders in a directory?
85 views (last 30 days)
I have one directory with many folders. Each folder contains a .txt file (eg, file1 contain number1.txt, file2 contain number2.txt etc). these files has 4 columns with double numbers.
Also I have, outside of this directories one matlab code that reads the .txt file, makes calculations and write a file with the results.
Is there a way to run tha matlab code for all the folders with automated manner? I mean to run the code with an easy way, and not running the matlab code one by one for each folder?
Stephen23 on 23 Apr 2021
Edited: Stephen23 on 23 Apr 2021
"Is there a way to run tha matlab code for all the folders with automated manner? "
Of course, just use DIR. For example:
P = 'absolute/relative path to the main folder';
S = dir(fullfile(P,'**','number*.txt'));
for k = 1:numel(S)
F = fullfile(S(k).folder,S(k).name)