I have 30 experimental trials that I logged on a DAQ and I read these in to MATLAB using xlsread.
I have a plot now where I show all 30 trials on one figure.
What I want to do is create a movie where it shows them plotting one by one.
Really I have a total of 60 line plots (30 inputs and 30 outputs), so it would be great if I could show the input and output for one, then the next, etc.
Right now my code is similar to this:
In_1 = xlsread(filename.xls, #1);
In_2 = xlsread(filename.xls, #2);
...
Out_1 = xlsread(filename.xls, #1);
Out_2 = xlsread(filename.xls, #2);
...
plot(t, In_1,'r')
plot(t, Out_1)
plot(t, In_2,'r')
plot(t, Out_2)
...
I've seen plenty of examples using getframe and movie. This does not help me, because I am plotting DATA. Not a function that is evaluated over a time interval. I am trying to plot 30 trials of data.
Use
avifile
to create an AVI file and thenaddframe
to capture each plotted graph you plot and convert it to a frame. I've also taken the liberty to addsubplots
to keep both plots in the same figure, and rewrite your code into a loop.Here's my (revised) suggested solution:
You can fiddle with the
avifile
options to control the quality of the generated video.Alos note that each
plot
sets the x and y axes according to the plotted values. If you want to keep the animation "smooth", you have to force the axes to remain constant for each graph, after every plot, using theaxis
command.Here is a simple example that should cover your needs.
Note: This will create an .avi file you can view in most multimedia players afterwards.
If you want the input and output plotted on two separate axes you can use
subplot
.The easiest way would be to use the
getframe
command in a for loop to put each plot in a frame and then play them back using themovie
command, this has some advantages (you can export the result as an avi, for instance) but it's quite slow sometimes, if you want to simply view the animation in matlab and need it to be somewhat faster you can refresh the data in the plot window and redraw it, it's a little more complex but it's explained quite well here Link.Also, type
help getframe
andhelp movie
in matlab for some explanations and examples as to how best use those commands.Hope this helps.