필터 지우기
필터 지우기

Iterations of copyfile function across files

조회 수: 2 (최근 30일)
julian gaviria
julian gaviria 2022년 6월 29일
답변: Abhijeet 2022년 7월 12일
I have 4 files (S001, S002, S003, S004) in the following path
C:\doss1\doss2\doss3\doss4\doss5\
Each file has a subfloder "rest_ctrl".
S001
rest_ctrl
S002
rest_ctrl
S003
rest_ctrl
S004
rest_ctrl
Aim: To copy and paste the files insde each file (indexed with the 'a*') in a different folder.
I defined the source and destination folders as follows:
SourcePath ='C:\doss1\doss2\doss3\doss4\doss5\';
Participant = 'S001';
SourceFolder = fullfile([SourcePath,Participant],'rest_ctrl');
And the destination folder as follows:
DistPath ='D:\doss1\doss2\doss3\doss4\doss5\doss6\';
DistFolder = fullfile(DistPath,'S001');
if ~exist(DistFolder)
mkdir(DistFolder)
end
The code works fine when I use the "copyfile" function subjectwise:
copyfile(fullfile(SourceFolder,'a*'),DistFolder);
How can I iterate it in order to have all the content of the source files (i.e., S001/ rest_ctrl/a... S004/ rest_ctrl/a...) in the destination folder?
Thanks in advance

채택된 답변

Abhijeet
Abhijeet 2022년 7월 12일
Hi Julian Gaviria,
I can understand that you want to do similar file operations on multiple file using for loop.
Please refer to this basic code template.
Here do_file_operation function takes in the file name like S001 and performs the required operation .
Participant = 'S00';
for i=1:4
suffix=num2str(i);
newParticipant=strcat(Participant,suffix);
%function for performing file operation
do_file_operation(newParticipant);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by