How to avoid ginput from becoming unresponsive to keyboard keys?
9 次查看(过去 30 天)
显示 更早的评论
I have written a simple function to keep ginputting and plotting points on the current axes, and deleting the last clicked point when the Backspace key is pressed, please see below. The while loop (normally) stops when I hit Enter key, which should return an empty value for [ix]
The code generally worked but depending on the number of points I define before hitting Backspace, the keyboard becomes unresponsive, and the Backspace key (or Enter key) does nothing (only mouse clicking works when that happens). Would anyone have an idea of what the issue could be please?
xpol=[]; ypol=[]; ix=0; p=0;
k=1;
while ~isempty(ix)
[ix,iy,key] = ginput(1); disp(key)
if ~isempty(key) && key~=8
xpol(k) = ix;
ypol(k) = iy;
p(k) = plot(xpol,ypol,'o-k','MarkerFaceColor','m','LineWidth',2);
k = k+1;
elseif ~isempty(key) && key==8
if k>1 % Make sure there is at least one point
k = k-1;
delete(p(k))
p(k) = [];
xpol(k) = [];
ypol(k) = [];
end
end
end
3 个评论
Yelena Bagdasarova
2018-11-28
编辑:Yelena Bagdasarova
2018-11-28
You know, I'm having major issues using the ginput function as well.
I'm running a R2018a install with updates on Linux. Ubuntu 18.04, and on an Asus VivoBook S laptop. I suspect it has something to do with Java, but I'm not knowlegable in that arena.
My I've transfered many of my old scipts using ginput onto this new computer/install, but I find that within the scripts (which are very busy creating new figures and plots) the ginput() function either is unresponsive to the return key and now that even with a call like ginput(2), it does not register the clicks and won't move on.
I've provided the first few lines of a function which uses ginput that I have this issue with. For this function, the figure does not come to the forefront while waiting for my input. So I have to find it among the previously plotted figures. The cursor is responsive and shows the selection cross but it does not go on after I've selected the said number of points.
Update: The function call is in a for loop, so it is called several times. When I put "drawnow" in front of ginput, it works the first time, but subsequent calls now call the ginput onto the wrong figure! I have a suspicion things just can't keep up.
Another Update: It seems that adding "pause(2)" before ginput works to have everything catch up before ginput is called.
function [freq,signal_Vmon,signal_Imon,signal_probe,pctVmon,pctImon,pctprobe]=FFTPlot(time, Vmon, Imon, probe,legendstring, figtitle,fig1title,fig2title)
pp = [1426 1 1855 1001]; %size of dell monitor
figure('Position', pp);
set(gcf,'DefaultAxesFontSize',15)
subplot(3,2,[1 2])
hold on
plot(time,Vmon)
plot(time,Imon)
if (not(isempty(probe)))
plot(time,probe,'r')
end
legend(legendstring)
%FFT
ind1 = 1;
ind2 = length(Vmon);
[x,y] = ginput(2);
ind1 = find(time > x(1),1,'first');
ind2 = find(time > x(2),1,'first');
...
end
回答(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!