Filter löschen
Filter löschen

sorting files into 2 separate folders

4 Ansichten (letzte 30 Tage)
Hoda
Hoda am 13 Feb. 2015
Bearbeitet: Hoda am 14 Feb. 2015
Hi I am trying to sort some DICOM files (1584), by separating them and saving them into 2 separate folders. the way i need to separate them is every alternating 8 files goes to one of the 2 folders. so i think i need start counting 1-8 and put in 1 folder and the next 8 go to the other folder. I'm not sure how to proceed this is what i have till now
% sorting alternating data
path = 'C:\Users\......';
output_dir = uigetdir('','C:\Users\Sorted_GE_SE_Images');
dirs = dir('C:\Users\GE_SE_Images\....\10_ep2d_ge_se_128_DCE\*.dcm')
N = length(dirs);
for i = 1 : N;
for j = 1:8;
file_SE = dirs(j).name
copyfile(file_SE,'C:\Users\\Sorted_GE_SE_Images\SE_images')
for k = 9:16;
file_GE = dirs(k).name
copyfile(file_GE,'C:\Users\Sorted_GE_SE_Images\SE_images')
end
end
end

Akzeptierte Antwort

per isakson
per isakson am 14 Feb. 2015
Maybe this will help you
sorting alternating data
path = 'C:\Users\......';
output_dir = uigetdir('','C:\Users\Sorted_GE_SE_Images');
dirs = dir('C:\Users\GE_SE_Images\....\10_ep2d_ge_se_128_DCE\*.dcm');
N = length(dirs);
for ii = 1 : 16 : N
sad = dirs(ii:min([N,ii+16]));
for jj = 1:length(sad)
file_SE = dirs(jj).name;
if jj<=8
copyfile( file_SE, 'C:\Users\Sorted_GE_SE_Images\SE_images')
else
copyfile( file_SE, 'C:\Users\Sorted_GE_SE_Images\GE_images')
end
end
end
  2 Kommentare
Hoda
Hoda am 14 Feb. 2015
Bearbeitet: per isakson am 14 Feb. 2015
Thanks alot Per, if you dont mind could you explain what this command
sad = dirs(ii:min([N,ii+16]));
does. Also tried to run your code but I get an error : Error using copyfile No matching files were found.
per isakson
per isakson am 14 Feb. 2015
The outer loop takes steps of 16 items of the file list except for the last where it takes the rest.
for ii = 1 : 16 : N
sad = dirs(ii:min([N,ii+16]));
sixteen items of the file list are copied to sad. The inner loop loops over the length of sad. Copying to sad makes the indexing simpler.
&nbsp
"Error using copyfile No matching files were found" &nbsp Replace
file_SE
by
fullfile( 'folder_name', file_SE )

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by