필터 지우기
필터 지우기

grabbing specific/not all files in a folder

조회 수: 3 (최근 30일)
Franziska Motka
Franziska Motka 2022년 8월 10일
댓글: Franziska Motka 2022년 8월 11일
Hi everyone,
I'm doing a fMRI analysis with a script I got from a collegue and adapted it for my purpose. Unfortunately, I stuck on one problem, so I would like to ask you for help. I have 320 .IMA files for each participant in a folder called "CUE*". Since the first 5 files are dummy scans, I only want to grab file 6 to 320 and ignore the first five. This is how the files are called: e.g. CBM210.MR.STUDIES_PSYCHOLOGY.0008.0001.2022.04.14.14.06.28.254369.304708762 with the 0001 in bold showing the numbers, running until 0320.
This is the respective part in the script, were I grab the .IMA files and work with them:
f
MRI_dir = fullfile(raw_dir, subFolder.name, 'STU*', 'CUE*');
func_files = dir(fullfile(fMRI_dir,'*.IMA'));
func_files_cell = orderFiles4SPM(func_files);
fprintf('%d func input files found...\n',length(func_files_cell))
matlabbatch{2}.spm.util.import.dicom.data = func_files_cell';
matlabbatch{2}.spm.util.import.dicom.outdir = {out_dir_func};
I was thinking about doing something like *[0006;0320]*.IMA or for i=1:nimg with i+5 but I could not make it so far...
Any help is more then welcome!
Best,
Franzi

채택된 답변

Walter Roberson
Walter Roberson 2022년 8월 10일
Unfortunately the wildcards that MATLAB accepts are only a subset of what is generally supported by the operating system. You will need to use other ways, such as
[~, basenames, ~] = fileparts({func_files.name});
prefixpattern = '(?<=\w+\.\w+\.\w+\.\w+\.)(\d+)';
prefixes = regexp(basenames, prefixpattern, 'match', 'once');
wanted = ~ismember(prefixes, {'0001', '0002', '0003', '0004', '0005'});
func_files = func_files(wanted);
  댓글 수: 1
Franziska Motka
Franziska Motka 2022년 8월 11일
Hi Walter,
thank you very much, it worked and saved me tons of time and clicking :)
Best,
Franzi

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by