loop Will only open the files in starting folder

I want to create a script that opens a folder and goes in to every subfolder and pulls out .mat files. The following code only pulls out the .mat files that are located in the starting fold even though it gathers all sub folder directories. Any help would be greatly appreciated!
startingFolder = pwd;
root = uigetdir(startingFolder);
allSubfolders = genpath(root);
subFolders = regexp(allSubfolders, ';', 'split');
for subFolderCount = 3 : length(subFolders)
% Get this subfolder.
thisSubFolder = subFolders{subFolderCount};
% Get a list of MAT files in this subfolder.
matFiles = dir(fullfile(thisSubFolder, '*.mat'));
end

 Akzeptierte Antwort

Voss
Voss am 19 Mai 2024

1 Stimme

matFiles = dir(fullfile(pwd,'**','*.mat'));

Weitere Antworten (0)

Kategorien

Mehr zu Environment and Settings finden Sie in Hilfe-Center und File Exchange

Produkte

Tags

Gefragt:

am 19 Mai 2024

Kommentiert:

am 20 Mai 2024

Community Treasure Hunt

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

Start Hunting!

Translated by