I have a loop in which I keep entering points into figure using ginput. I would like the loop to run until user presses a key, Heres what I have:
function enter_points()
f = figure();
axis([-1 1 -1 1]);
coorX = [];
coorY = [];
while 1
[x, y] = ginput(1);
coorX = [coorX x];
coorY = [coorY y];
waitforbuttonpress;
key = get(f,'CurrentCharacter');
if (key == 'e')
display('End of cycle.')
break;
else
display('Enter next point')
end
end
coor = [transpose(coorX) transpose(coorY)];
display(size(coor));
display(coor);
end
The problem with this code is, that I haveto press a key to continue entering points. Another problem is, that Matlab sometimes freezes when running this code (Im not sure it the code is the reason or something else is). And how to detect pressing “enter” instead of “e”? Thanks for any help
Why don’t you use the builtin: