Effacer les filtres
Effacer les filtres

Iterations of copyfile function across files

4 vues (au cours des 30 derniers jours)
julian gaviria
julian gaviria le 29 Juin 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

Réponse acceptée

Abhijeet
Abhijeet le 12 Juil 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

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Report Generator dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by