How to plot animated graph from a matrix of data?

25 views (last 30 days)
I am trying to create an animated plot from a matrix of data that is approximately 1500x250 (250 data points per plot and 1500 plots).
I have looked at the movie and getframe commands, but it seems like i would have to plot each of the 1500 rows to getframe and then display it using the movie function. As this size matrix is a small sample compared to some of the data i will be collecting in the future, is there a way to parse this data or save the frames without having to plot each row first?
If anyone would be able to point me to a simpler or less resource intensive way to animate the data from a matrix it would be vey helpful, or correct me if i am misunderstanding how the getframe and movie functions work it would be much appriciated.
Thanks for any help provided.

Answers (1)

Dave B
Dave B on 28 Sep 2021
Edited: Dave B on 28 Sep 2021
In some sense, you are going to need to plot each row and capture each frame, as you want each frame of the movie to contain new plotted data. However you can make this a little more lightweight (and a little faster) by setting data properties on the line object before each getframe. This saves the overhead of creating the object (and clearing the axes etc.), and will save you having to respecify configuration of the line object (color, width, etc.) and the axes (title, labels, etc.)
X = rand(100,20);
h=plot(X(1,:));
fr=getframe; %I don't think there will be much benefit to a more careful initialization here...
for i = 2:height(X)
h.YData = X(i,:);
fr(i) = getframe;
% or if you just want to watch it and you don't care about the playback
% speed, consider 'drawnow limitrate'
end
% write a video file, or call movie

Categories

Find more on Animation in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!