Azzera filtri
Azzera filtri

Improve figure update speed with WindowsButtonMotionFcn

2 visualizzazioni (ultimi 30 giorni)
Hi all,
I have a WindowsButtonMotionFcn defined to essentially move a lineobject on my axes to where my cursor is. Unfortunately, there is a lag between my mouse movements versus the changing of the x / ydata of the lineobject, so as I am moving my cursor around the lineobject is playing catchup with my cursor. I know there will be some slight lag due to perhaps the processing speed of my desktop, but I am wondering if there are ways that I can improve my code / make the figure update quicker. I've tried the drawnow function but it doesnt seem to have made a significant difference.
for reference, I've added my function below w/ some comments.
function mouseMove(self,hObj,event)
cp = get(hObj,'CurrentPoint'); %hObj is my figure
if isempty(cp)
return
end
%below is just logic of when i want the lineobject to be plotted / moved,
% based on whether or not my cursor is within a particular area of my figure.
if and(cp(1) >= self.ax2.Position(1) && cp(1) <= self.ax2.Position(1) + self.ax2.Position(3),...
cp(2) >= self.ax2.Position(2) && cp(2) <= self.ax1.Position(2) + self.ax1.Position(4))
center = self.ax2.Position(1) + self.ax2.Position(3)/2;
ratio = (self.ax2.Position(1)+self.ax2.Position(3) - center)/self.ax2.XLim(2); %pixel / point on axes
map_x = (cp(1) - center)/ratio;
if isempty(self.cursor1) % if object did not exist, plot it.
%
self.cursor1= plot(self.ax1,[map_x map_x] ,self.ax1.YLim ,'-r','Tag','cursor1');
self.cursor2 = plot(self.ax2,[map_x map_x],self.ax2.YLim,'-r','Tag','cursor2');
uistack(self.cursor1,'bottom')
uistack(self.cursor2,'bottom')
else
%
self.cursor1.XData = [map_x map_x]; % Here is where I actually move the position of the lineobject
self.cursor2.XData = [map_x map_x]; % moving the position of another lineobject.
%drawnow limitrate;
end
else
end
end
The code is fairly simple, and adding a tic / toc reports that it runs in about .008s.
get current point > check if current point is within an area > check if line object exists > if yes then move> if not then plot > repeat.
Any insight will be greatly appreciated! Let me know if I need to provide more background info.
  2 Commenti
Rik
Rik il 11 Mar 2019
It looks to me like you are already at the limit of what you can expect from such a function. You could try running the profiler (even if that is a bit tricky considering the interactive nature of this function).
In a recent question I found that the object notation is faster than the set syntax, so that is already at the optimum.
The drawnow command will simply trigger a graphics update, so that might even cause a slowdown.
The only thing I can think of is removing the two checks and simply making sure the callback is only set if the object exists.
Kevin Phung
Kevin Phung il 11 Mar 2019
darn, I was hoping that I may have not been using the drawnow function correctly, so that I can possibly improve there. The checks are definitely necessary because I only want my function to plot when it is hovering over my subplots (or between them). I've never heard of the profiler-- so I'll check it out

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by