A follow up question would be, what if these subfolders are all on a dropbox link and there are more than 10 of them (far too large too download them all to my computer). Is there any way I can access these subfolders in MATLAB to use my function on them iteratively? Thanks.
Want to iterate over subfolders within folder
조회 수: 26 (최근 30일)
이전 댓글 표시
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
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
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!