Help with For Loop

2 views (last 30 days)
Ian
Ian on 1 Mar 2013
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);

Accepted Answer

Walter Roberson
Walter Roberson on 1 Mar 2013
i = 1;
while i <= total_no_images
...
if strcmpi(accept, 'Yes')
close
continue;
end
filename = ...
...
i = i + 1;
end
  1 Comment
Ian
Ian on 2 Mar 2013
Works perfectly, thank you so much!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!