How to make an animated stairstep graph?

7 views (last 30 days)
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)

Accepted Answer

jonas on 14 Jun 2018
Edited: jonas on 14 Jun 2018
You can use the comet() function if you manipulate the data a bit.
a=[0 1 0 1 0 1 0 0 1 1 0];
aq = interp1(x,a,xq,'previous');
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.
Tai Jia Xun
Tai Jia Xun on 16 Jun 2018
Thank you very much Jonas!!!!

Sign in to comment.

More Answers (0)


Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by