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

 채택된 답변

Voss
Voss 2024년 5월 19일

1 개 추천

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

제품

태그

질문:

2024년 5월 19일

댓글:

2024년 5월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by