Filter löschen
Filter löschen

Iterations of copyfile function across files

1 Ansicht (letzte 30 Tage)
julian gaviria
julian gaviria am 29 Jun. 2022
Beantwortet: Abhijeet am 12 Jul. 2022
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

Akzeptierte Antwort

Abhijeet
Abhijeet am 12 Jul. 2022
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

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB Report Generator finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by