Running a for loop with breaks

조회 수: 5 (최근 30일)
Reed Harper
Reed Harper 2021년 1월 18일
답변: Cris LaPierre 2021년 1월 18일
My goal is to get coordinates using ginput, and then asking the user if there is another set of coordinates to pick. if yes continuing looping and get another set of coord. from ginput, if no, then I'd like to break out of the loop. When I use the code below no matter my input to the yes/no, it already moves to selecting new points. Thoughts?
for n=1:12
[temp(:,1),temp(:,2)]=ginputc('Color','r','ShowPoints',true);
platelets{k}{p}=[temp(:,1),temp(:,2)];
p=p+1;
plateCheck=input('\nIs there an untagged platelet in frame, 1 for yes 0 for no.\n');
if plateCheck == 0
break;
else
end
end
  댓글 수: 1
Bob Thompson
Bob Thompson 2021년 1월 18일
I had to remove the ginputc portion of this code, but doing so made it run fine for me.
Are you sure you're not overwriting the plateCheck value within ginputc somehow? I can't imagine this being the case, but it's the only thing that doesn't seem to add up to me.

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

답변 (1개)

Cris LaPierre
Cris LaPierre 2021년 1월 18일
First point - you are not using ginput. You are using ginputc, which is a function obtained on the file exchange.
From the description provided there, you will see that ginputc will continue collecting points until you press the return key.
  • [X,Y] = ginputc gathers an unlimited number of points until the return key is pressed.
I suspect the return key must be pressed when the figure is in focus. The input command is switching the focus to the command window. Try specifying how many points you want the user to select in each loop to avoid this behavior.
  • [X,Y] = ginputc(N) gets N points from the current axes and returns the X- and Y-coordinates in length N vectors X and Y.

카테고리

Help CenterFile Exchange에서 Visual Exploration에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by