Help with For Loop

2 次查看(过去 30 天)
Ian
Ian 2013-3-1
Hey there,
This is apart of a larger code so I've entered a value for total_no_images for ease. I want the user to have an option if the image taken is blurry etc so I've tried to sort it out and researched break/return/continue but not managed to get it quite right. I need the program to take a certain amount of images so don't want it to increment if the first image taken is wrong. Would a switch be better? Any help offered is greatly appreciated!
Thanks!
% Hardware Configuration, set image size
vid = videoinput('winvideo', 1);
% Preview video
start(vid);
preview(vid);
total_no_images=3;
for i = 1:total_no_images
fprintf('Take image %d of %d. Type Yes when ready. \n', i, total_no_images)
decide=input('','s');
if strcmp(decide,'Yes') % Compare two strings
img = getsnapshot(vid); % Capture image
image(img); % Preview image
fprintf('Would you like to retake the image? Yes or No. \n')
accept=input('','s');
if strcmp(accept,'Yes') % Compare two strings
close; % Close preview image
return % If image unacceptable restart
else
filename = ['Image ' num2str(i)]; % Make a file name
imwrite(img, filename, 'bmp'); % Save file as BMP
close; % Close preview image
end
end
end
%Delete and close video preview
close(vid);
closepreview(vid);
delete(vid);

采纳的回答

Walter Roberson
Walter Roberson 2013-3-1
i = 1;
while i <= total_no_images
...
if strcmpi(accept, 'Yes')
close
continue;
end
filename = ...
...
i = i + 1;
end

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by