MATLAB: Sorting files into 2 separate folders

2 sepearte foldersalternating sortingdir

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

Best Answer

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