Azzera filtri
Azzera filtri

Iterations of copyfile function across files

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Abhijeet
Abhijeet il 12 Lug 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

Più risposte (0)

Categorie

Scopri di più su MATLAB Report Generator in Help Center e File Exchange

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by