フィルターのクリア

How to make an animated stairstep graph?

5 ビュー (過去 30 日間)
Tai Jia Xun
Tai Jia Xun 2018 年 6 月 14 日
コメント済み: Tai Jia Xun 2018 年 6 月 16 日
I have a stairstep graph (squarewave) plotted from an array, is it possible to make the graph plot in motion?
%%my code: x=[0:1:10]; a=[0 1 0 1 0 1 0 0 1 1 0]; stairs(x,a)

採用された回答

jonas
jonas 2018 年 6 月 14 日
編集済み: jonas 2018 年 6 月 14 日
You can use the comet() function if you manipulate the data a bit.
x=[0:1:10];
a=[0 1 0 1 0 1 0 0 1 1 0];
xq=0:0.01:10;
aq = interp1(x,a,xq,'previous');
comet(xq,aq)
There is also a similar function called animatedline() which I have never tested. Or as a third, perhaps simplest solution, plot point-by-point in a for-loop using pause(t) in every loop.
  3 件のコメント
jonas
jonas 2018 年 6 月 15 日
It does not appear to be possible. Option two works fine though:
x=[0:1:10];
a=[0 1 0 1 0 1 0 0 1 1 0];
%Increase resolution (step size determines speed of animation)
xq=0:0.0001:10;
aq = interp1(x,a,xq,'previous');
figure;
h=animatedline
%Change properties
set(h,'color','r','linewidth',2)
axis([0 10 0 1])
for k = 1:length(aq)
addpoints(h,xq(k),aq(k))
drawnow update
end
Tai Jia Xun
Tai Jia Xun 2018 年 6 月 16 日
Thank you very much Jonas!!!!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by