Borrar filtros
Borrar filtros

Iterations of copyfile function across files

2 visualizaciones (últimos 30 días)
julian gaviria
julian gaviria el 29 de Jun. de 2022
Respondida: Abhijeet el 12 de Jul. de 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

Respuesta aceptada

Abhijeet
Abhijeet el 12 de Jul. de 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

Más respuestas (0)

Categorías

Más información sobre MATLAB Report Generator en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by