loop Will only open the files in starting folder

11 ビュー (過去 30 日間)
Bertrand
Bertrand 2024 年 5 月 19 日
コメント済み: Bertrand 2024 年 5 月 20 日
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 日
matFiles = dir(fullfile(pwd,'**','*.mat'));
  1 件のコメント
Bertrand
Bertrand 2024 年 5 月 20 日
Exactly what I needed.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by