Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

How to create a movie and play it instead of using a for loop of plots

Asked by S Simeonov on 24 Nov 2011

I have a cell (Nx1) which contains data (x,y,z coordinates). I then proceed to create N plots in a for loop which results in a movie like output.

However, I would like to be able to collect all the plots (silently) in a movie and then play it, save it etc.

I've found this:

http://www.mathworks.co.uk/support/tech-notes/1200/1204.html#Section%2010

but I don't know how this helps when you have various plot commands each of which draws a new plot.

0 Comments

S Simeonov

Products

No products are associated with this question.

2 Answers

Answer by Naz on 24 Nov 2011

Here is what I use. Don't know if it will work as is, but first it should play it (as a sequence of frames of 3D matrix DATA) and then play it again after saving to 'outFileName'... Don't remember exactly.

fig1 = figure(1);
winsize = get(fig1, 'Position');
winsize(1:2) = [0 0];
winsize(3:4) = winsize(3:4)*1.5;
numframes =total;
A = moviein(numframes, fig1, winsize);
set(fig1, 'nextplot', 'replacechildren');
for i = 1:numframes
    imagesc(DATA(:,:,i), [0 0.3]); axis image; axis off; colormap gray
    title(num2str(i));
    A(:,i) = getframe(fig1, winsize);
end
frame_rate = 10;
movie(fig1,A,1,frame_rate, winsize)
movie2avi(A,num2str(outFileName), 'fps', frame_rate)

*In 'imagesc' line the term [0 0.3] is for contrast (you might not needed).

0 Comments

Naz
Answer by Nino on 11 Jun 2013

Hello NAz, you answer is clear. but, suppose to have a trajectory defined in an array 3D+time (x,y,z,t). how is possible tu play the trajectory and read the time value on the plot by pointing the mouse on the graph?

0 Comments

Nino

Contact us