Improve figure update speed with WindowsButtonMotionFcn
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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
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.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Graphics Performance in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!