Mouse speed (frustratingly) slow when using ginput in R2015b

10 views (last 30 days)
I often use ginput in my scripts to select a region in which to search for local maxima in my data sets.
Something like this:
x = -10:10;
y = .01*x.^4-x.^3-2*x.^2+20*x-1;
figure('units','normalized','outerposition',[0 0 1 1])
plot(x,y);
[Xs, ~] = ginput(2);
I1 = find(x < Xs(1), 1);
I2 = find(x > Xs(2), 1);
LocalMax = max(y(I1:I2));
Now that I've upgraded to R2015b, the pointer moves very slowly when I'm using ginput. I've noticed this only occurs when I force the figure window to be full-screen, but I need the window to be large so I can see my data clearly.
  1 Comment
Nam Hoang Le
Nam Hoang Le on 16 Sep 2016
I have the same problem. Someone can help. I have Core I7, RAM 8GB, so I do not think it is because of PC

Sign in to comment.

Answers (4)

Benigno Barbés Fernández
I have the same problem. It began when I upgraded from 2014b to 2016b. Any hint?

Yura Polyachenko
Yura Polyachenko on 12 Aug 2017
I had the same problem. I needed ginput(1) and finally found that it can be replaced with
function axes_ButtonDownFcn(hObject, eventdata)
...
crd = get (gca, 'CurrentPoint');
y = crd(1,2);
x = crd(1,1);
...
end
if you need N points it can be something like this
% these vars are some kind of global vars, e.g. handles can be used.
N = 10;
ind = 0;
x = zeros(1,N);
y = zeros(1,N);
function axes_ButtonDownFcn(hObject, eventdata)
if(ind<N)
ind = ind+1;
c = get (gca, 'CurrentPoint');
y(ind) = c(1,2);
x(ind) = c(1,1);
else
% we are here after getting N points
N = 0;
do_smth_with_point(x,y,some_data);
end
end
Try to play with 'CurrentPoint' somehow anyway

Jan
Jan on 12 Aug 2017

Benigno Barbés Fernández
Hi.
I tried the solution of Yura (using the function axes_ButtonDownFcn instead of ginput), but I am unable to use it. I'm very new with matlab: be patient
I wrote;
hfig=figure;
imshow('whatever');
ginput(1) % painfully slow
axes_ButtonDownFcn(hfig, 1) % the "1" is because I don't know what I'm supposed to put
function axes_ButtonDownFcn(hObject, eventdata)
crd = get (gca, 'CurrentPoint');
y = crd(1,2)
x = crd(1,1)
end
The result: it shows the position of the mouse... But I wanted it to wait until I press the mouse button
Can you help me
  1 Comment
Dmitry Kaplan
Dmitry Kaplan on 3 Oct 2018
Edited: Dmitry Kaplan on 3 Oct 2018
Sure. 1. The reason why ginput() is slow is simple: matlab is becoming a huge bolted-on beast of a code base that doesn't get sufficient usability testing. ginput() used to be very quick and then something happened...
2. The first reason why your code doesn't work is that the buttondown function needs to be defined and then assigned to something. So, do yourself a favor a define a completely seperate function
function print_current_loc_at_button_press(hObject, eventdata)
crd = get (gca, 'CurrentPoint');
fprintf('CurrentLoc is: %f, %f\n', crd(1,1), crd(1,2));
end
3. Assigning this function:
h = imshow('whatever'); set(h,'ButtonDownFcn',@print_current_loc_at_button_press);
Notice that the function is assigned to the object (the image), and not to the axis as previous responders suggested. Assigning the callback to the axis only works for me if the chart contains "regular" graphics, and not an image. Supposedly, fiddling with Hittest properties of gca and h may address this, but the way above is more better :-)

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!