How can I speed up drawnow when combined with 'get' function?

8 Ansichten (letzte 30 Tage)
Silvano Gefferie
Silvano Gefferie am 24 Jan. 2022
Kommentiert: Silvano Gefferie am 27 Jan. 2022
Dear community,
I have been trying to speed up the use of drawnow, employed to update the x-axis (and thereby creating a horizontally 'moving' window along the plotted curve's trajectory), for a while now. The problem is that it is slowed down by a call to the get-function for fetching the live co-ordinates of my cursor, every time I move it over the figure. I have already tried a few things, such as
(1)
drawnow limitrate
(2)
the alternative use of
pause(0.005)
and combinations of the above attempts (with different pausing duration and calling the pause function only for multiples of iteration numbers such as 5). Unfortunately, nothing has resulted in the fluently updated figure with instant cursor coordinates that are acquired when I move my mouse.
Basically, the code that I use is
fig1 = figure;
set(fig1, 'WindowButtonMotionFcn', @mouseMove);
for n=1:1:numel(x)
axis([x(n) x(n+1) -1.2 1.2]);
set(gca, 'XTick', [])
set(gca, 'YTick', [])
% % drawnow
% % pause(0.005)
end
with x being the array with values for the horizontal axis (code for making the plot is omitted), and the mouseMove function being:
function mouseMove(varargin)
% Get live cursor coordinates
C = get(gca, 'CurrentPoint');
Anyone who knows how to tackle this issue?
Thank you in advance.
Silvano.

Antworten (1)

Steven Lord
Steven Lord am 27 Jan. 2022
So it sounds like you're trying to do horizontal panning. Is that correct? You can't actually pan the figure shown in this Answer but if you run that code in your MATLAB session you can pan. Because I used "xon" as the option to the pan function you can pan left and right but not up and down.
x = 0:720;
y = sind(x);
plot(x, y)
axis([0 180 -1 1])
pan xon
  1 Kommentar
Silvano Gefferie
Silvano Gefferie am 27 Jan. 2022
Hello Steven Lord,
Thank you for answering. I think I might have slightly misphrased my question.
So, actually, I wouldn't like to (manually, by mouse-shift) pan the figure, but I'd like to create an animated sinusoid by constantly updating the x-axis. This creates some sort of shift of the window over the sin wave, making it look like it's moving.
The following video may explain what I mean: Sine wave animation
And then, the animation should not "stutter" while I hover my mouse cursor over it, during which the X- and Y-coordinates of the cursor are updated (upon each movement).
Best,
Silvano

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by