Mouse speed (frustratingly) slow when using ginput in R2015b
18 次查看(过去 30 天)
显示 更早的评论
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 个评论
Nam Hoang Le
2016-9-16
I have the same problem. Someone can help. I have Core I7, RAM 8GB, so I do not think it is because of PC
回答(4 个)
Benigno Barbés Fernández
2017-3-5
I have the same problem. It began when I upgraded from 2014b to 2016b. Any hint?
0 个评论
Yura Polyachenko
2017-8-12
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
0 个评论
Benigno Barbés Fernández
2018-8-27
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 个评论
Dmitry Kaplan
2018-10-3
编辑:Dmitry Kaplan
2018-10-3
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 :-)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!