Indexing in nonsequential order
The following code copy files from the source folder to a destination folder:
SourcePath =’/f1/f2/f3/f4/f5/f6/f7/f8/’;
index = [00001]
%iteration for the 9th subfolder
for i = 1 : length(index)
newParticipant=num2str(index(i));
T = [‘sub-m’,newParticipant];
SourceFolder = fullfile([SourcePath,T],’f10/f11′)
%Destination folder is the current directory + DistFolder
DistFolder = fullfile(‘d1′,T,’d3’);
[X,Y,Z] = copyfile(fullfile(SourceFolder,’*y_file.chik.chik’), …
DistFolder);
end
Question: How can I automate the index when the subbfolder’s name (see above 9th subfolder) are 5-digits non sequential numbers?. The codeline
index = 00001 : 02500;
yileds an undesired output: It will create multiple empty folders in "distfolder".
For instance, the first file to copy is located in
SourceFolder = ‘/f1/f2/f3/f4/f5/f6/f7/f8/sub-m00001/f10/f11’
The Line index = 00001 : 02500; will create 120 empty files, since the second file to copy is located in
SourceFolder = ‘/f1/f2/f3/f4/f5/f6/f7/f8/sub-m00121/f10/f11’The following code copy files from the source folder to a destination folder:
SourcePath =’/f1/f2/f3/f4/f5/f6/f7/f8/’;
index = [00001]
%iteration for the 9th subfolder
for i = 1 : length(index)
newParticipant=num2str(index(i));
T = [‘sub-m’,newParticipant];
SourceFolder = fullfile([SourcePath,T],’f10/f11′)
%Destination folder is the current directory + DistFolder
DistFolder = fullfile(‘d1′,T,’d3’);
[X,Y,Z] = copyfile(fullfile(SourceFolder,’*y_file.chik.chik’), …
DistFolder);
end
Question: How can I automate the index when the subbfolder’s name (see above 9th subfolder) are 5-digits non sequential numbers?. The codeline
index = 00001 : 02500;
yileds an undesired output: It will create multiple empty folders in "distfolder".
For instance, the first file to copy is located in
SourceFolder = ‘/f1/f2/f3/f4/f5/f6/f7/f8/sub-m00001/f10/f11’
The Line index = 00001 : 02500; will create 120 empty files, since the second file to copy is located in
SourceFolder = ‘/f1/f2/f3/f4/f5/f6/f7/f8/sub-m00121/f10/f11’ The following code copy files from the source folder to a destination folder:
SourcePath =’/f1/f2/f3/f4/f5/f6/f7/f8/’;
index = [00001]
%iteration for the 9th subfolder
for i = 1 : length(index)
newParticipant=num2str(index(i));
T = [‘sub-m’,newParticipant];
SourceFolder = fullfile([SourcePath,T],’f10/f11′)
%Destination folder is the current directory + DistFolder
DistFolder = fullfile(‘d1′,T,’d3’);
[X,Y,Z] = copyfile(fullfile(SourceFolder,’*y_file.chik.chik’), …
DistFolder);
end
Question: How can I automate the index when the subbfolder’s name (see above 9th subfolder) are 5-digits non sequential numbers?. The codeline
index = 00001 : 02500;
yileds an undesired output: It will create multiple empty folders in "distfolder".
For instance, the first file to copy is located in
SourceFolder = ‘/f1/f2/f3/f4/f5/f6/f7/f8/sub-m00001/f10/f11’
The Line index = 00001 : 02500; will create 120 empty files, since the second file to copy is located in
SourceFolder = ‘/f1/f2/f3/f4/f5/f6/f7/f8/sub-m00121/f10/f11’ index, copyfile MATLAB Answers — New Questions