Problem with loop: Round 1

조회 수: 1 (최근 30일)
Frank
Frank 2011년 5월 20일
Hello!
I'm having difficulties with this script. It asks the user to select a directory and then makes a file in the selected directory. Then within the directory are several images of different sizes, the script only takes certain images of a specific size and writes them into the folder target. However, It writes all the folders within the selected directory, not "target". Can anyone help?
Thanks
-Frank
Code:
source_dir = uigetdir();
cd(source_dir);
mkdir('Target')
dest_dir = [pwd '/Target'];
directory = dir( '*.tif');
for ii = 1:length(directory)
I = imread(directory(ii).name);
[Y X] = size(I)
if X ~= Y && X < 400
imwrite(I,[dest_dir, directory(ii).name]);
end
end

채택된 답변

Sean de Wolski
Sean de Wolski 2011년 5월 20일
You need a '/' after target.
dest_dir = [pwd '/Target/'];
  댓글 수: 1
Frank
Frank 2011년 5월 20일
I hate when one character messes with the entire script.
Works great, Thank you!

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

추가 답변 (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