필터 지우기
필터 지우기

Create a filelist with files (ending in _BTcom.mat) from different subfolders (all the subfolders are in the same folder)

조회 수: 3 (최근 30일)
HI,
I am trying create a filelist from files in different subfolders. All the files are in the same main folder 'C:\Users\paola\Desktop\MATLAB\20mM-new'. I wrote this but it doesn't really work
folder='C:\Users\paola\Desktop\MATLAB\20mM-new'
d=dir(folder)
subf=d([d.isdir])
for k=1:numel(subf)
subfolder=subf(k).name
subf1=fullfile(folder,subfolder)
f=dir([subf1 '\*_BTcom.mat'])
for ii=1:numel(f)
file=fullfile(subf1,f(ii).name);
end
end

답변 (1개)

Thomas Jensen
Thomas Jensen 2021년 4월 13일
Hi Paola,
The best approach to search for files inside subfolders is creating a recursive function.
  댓글 수: 4
Thomas Jensen
Thomas Jensen 2021년 4월 13일
Hi Paola,
Sorry it did not work for you. I tested on Matlab 2017b and it worked fine. The file list is displayed in the command window.
Could you please confirm that you are calling the function my_filelist('C:\Users\paola\Desktop\MATLAB\20mM-new') and what is displayed in the command window?
Best regards,
Paola
Paola 2021년 4월 13일
It doesn't let me call the function my_filelist('C:\Users\paola\Desktop\MATLAB\20mM-new') so I create a variable folder=['C:\Users\paola\Desktop\MATLAB\20mM-new'] and run your script but it displays just the name of the folder. Sorry I am new with matlab

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by