How can I recursively process files in subdirectories using MATLAB?
Show older comments
How can I recursively process files in subdirectories using MATLAB?
I have files located in multiple subdirectories within a directory. I would like to be able to process the data in each subdirectory using the same functions. How can I do this without having to manually run the code in each directory?
Accepted Answer
More Answers (1)
lvn
on 11 Mar 2020
It is high time Matlab updates some of the official answers, as many are outdated.
This is an example, as of R2016b, no need for external tools:
files=dir('C:\temp\**\*.txt');
for k=1:length(files)
fn=fullfile(files(k).folder, files(k).name);
%process the file fn here
end
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!