Running a for loop with breaks

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 Kommentar

Bob Thompson
Bob Thompson am 18 Jan. 2021
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Cris LaPierre
Cris LaPierre am 18 Jan. 2021

0 Stimmen

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.

Kategorien

Mehr zu Data Exploration finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 18 Jan. 2021

Beantwortet:

am 18 Jan. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by