Friday, April 29, 2005

[t] making movies in Matlab

In matlab, a series of plotting can be recorded as a movie. Use a frame array to store the frames, then play them back either in Matlab or save to a AVI file.

I made one for the waveforms. However, the AVI file is a bit oversized, due to the lackness of effienent compressor.

Sample code is listed as following:
clear; clf;

load max_flx_0;
extensor=max_flx_0(:,5);
flexor=max_flx_0(:,4);
torque=max_flx_0(:,3);

moviefile=avifile('coac2.avi','compression','None');
segmentsize=10;
for j=1:(2500/segmentsize);
hold on;
subplot(3,1,1); plot(extensor(1:j*segmentsize),'g');
axis([0 3000 -5 5]);
hold on;
subplot(3,1,2); plot(flexor(1:j*segmentsize),'g');
axis([0 3000 -5 5]);
hold on;
subplot(3,1,3); plot(torque(1:j*segmentsize),'g');
axis([0 3000 -2 2]);
moviefile=addframe(moviefile, getframe(gcf));
end

moviefile=close(moviefile);

[edited on 05/11/05]
I found a very good AVI compressor: it compressed my 300M avi file to 1.3M mpg, cool!