필터 지우기
필터 지우기

sorting files into 2 separate folders

조회 수: 4 (최근 30일)
Hoda
Hoda 2015년 2월 13일
편집: Hoda 2015년 2월 14일
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

채택된 답변

per isakson
per isakson 2015년 2월 14일
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
Hoda
Hoda 2015년 2월 14일
편집: per isakson 2015년 2월 14일
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 2015년 2월 14일
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 )

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by