Running a for loop with breaks
4 次查看(过去 30 天)
显示 更早的评论
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
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
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Visual Exploration 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!