ginput not working with R2015a for handling two figures

4 views (last 30 days)
I have two open figures in MATLAB and I want the user to be able to get graphical input from both the figures, by calling ginput on one figure at a time and switching control between the two figures. I have the following code that does this, which works perfectly well in R2013a,b:
h1 = figure;
h2 = figure;
h = h1;
while 1
figure(h);
[x, y, sig] = ginput(1);
disp(['x is ' num2str(x) ', y is ' num2str(y) ', sig is ' num2str(sig)]);
if sig == 49
% 1 has been pressed
h = h1;
elseif sig == 50
% 2 has been pressed
h = h2;
elseif sig == 3
% Right click pressed
break
end
end
The above code starts with calling ginput on figure h1 and keeps receiving graphical inputs until 2 is pressed, which switches the control to figure h2. Pressing 1 switches the control back to figure h1. Pressing right click terminates this operation.
When I run this code in MATLAB R2015a, a stale crosshair appears on figure h1 which neither receives any graphical input from ginput, nor allows the user to switch between the two figures.
Has anyone else encountered a similar problem while using ginput in R2015a? It would be great if someone can find a solution to this problem.
Thanks,
Anuj
  1 Comment
Andrew Philippides
Andrew Philippides on 10 Nov 2015
I have the same issue. Very like your problem, I am calling ginput sequentially in figure 1. However, I then plot something in figure(2) before going back to figure(1) and calling ginput and it fails. This code worked fine in previous mntlab versions

Sign in to comment.

Answers (1)

Andrew Philippides
Andrew Philippides on 10 Nov 2015
I have just called technical support and found the work around. It's a known bug and to get round it, after every call to a new figure (or probably any figure) you need to call drawnow

Categories

Find more on Visual Exploration in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!