フィルターのクリア

Want to iterate over subfolders within folder

27 ビュー (過去 30 日間)
Shri Chand
Shri Chand 2023 年 3 月 23 日
コメント済み: Shri Chand 2023 年 3 月 27 日
I have a current working director or folder in MATLAB and wrote a function in this directory. Within this directory, I have a folder that contains 10 subfolders, each of which contains two different types of files (one is .edf and one is .xlsx). My function is designed to take an edf file and the corresponding xlsx file and compute something based on these.
So, my goal is to find a way that I can loop through these 10 subfolders and call my function on the edf and xlsx files in each subfolder one by one. Is there any way I can do this? Thanks.
  4 件のコメント
Shri Chand
Shri Chand 2023 年 3 月 23 日
@Jon, thanks for your response. I looked at the dir command and tried using this. I am just not sure how to iterate through folders in dir to call the function on each of these subfolders. The documentation for dir did not have any examples of how to do this.
Rik
Rik 2023 年 3 月 23 日
The point is that nothing in your question actually requires itterating through folders, only through file pairs. And dir can generate that list of files for you.

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

採用された回答

Fangjun Jiang
Fangjun Jiang 2023 年 3 月 23 日
Files=dir('**/*.xlsx') will give you a list of all the .xlsx files in the folder and sub-folder.
Observe Files(1), Files(2), ...
Use a for-loop to go through all the files in your program, use fileparts() to get the folder name. Use fullfile() to get the full path of the .edf file if needed.
  7 件のコメント
Fangjun Jiang
Fangjun Jiang 2023 年 3 月 26 日
xlsread(fullfile(Files(1).folder, Files(1).name))
Shri Chand
Shri Chand 2023 年 3 月 27 日
@Fangjun Jiang Thanks very much for your help!

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by