フィルターのクリア

Alternatives to "drawnow"

8 ビュー (過去 30 日間)
David Corella López
David Corella López 2020 年 12 月 22 日
回答済み: Cris LaPierre 2020 年 12 月 23 日
Hi!
I'm trying to plot a moving graph, using the "drawnow" function. Nevertheless, I am wondering whether it is possible to control the plotting pace.
I'm using "pause" function, but there also are instabilities. Is there an alternative to avoid them?
Furthermore, I'd like to know if there's a way to stop the plotting process (besides from the pause button).
My code is:
clear
clc
close
t3=linspace(0, 500, 2000);
x2=linspace(0, 10, 100);
%for n=1:leng
for i=1:length(t3)
y2=3*sin(0.5*x2-0.1*t3(i)-0.3);
plot(x2, y2)
%xlabel('x(m)','FontSize',15)
%ylabel('y(t, x) (m)','FontSize',15)
drawnow
pause(0.01)
end
Thank you!!
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 12 月 22 日
There is drawnow limitrate which limits to 20 fps.

サインインしてコメントする。

採用された回答

Cris LaPierre
Cris LaPierre 2020 年 12 月 23 日
It looks like your x data never changes. That should mean your number of y points also remains constant. One thing to try is to just update the YData rather than creating a new plot.
As for how to stop it manually, you could attach a callback to your figure to detect either a key press or a click in an empty part of the figure window. You can read more about the available callbacks here.
t3=linspace(0, 500, 2000);
x2=linspace(0, 10, 100);
y2=3*sin(0.5*x2-0.1*t3(1)-0.3);
stopAnimation=0;
fig = figure('Visible',"on",...
'KeyPressFcn',@keyPress, ...
'ButtonDownFcn',@buttonPress)
h = plot(x2, y2);
xlabel('x(m)','FontSize',15)
ylabel('y(t, x) (m)','FontSize',15)
for i=2:length(t3)
if stopAnimation
break
end
y2=3*sin(0.5*x2-0.1*t3(i)-0.3);
h.YData = y2;
drawnow limitrate
pause(0.01)
end
function keyPress(H,E)
assignin('base','a',1)
end
function buttonPress(H,E)
assignin('base','a',1)
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by