Thread Subject:
Video, created with Matlab, shows only first frame during the whole video?!

Subject: Video, created with Matlab, shows only first frame during the whole video?!

From: Koos

Date: 15 Jun, 2012 17:47:06

Message: 1 of 3

Hello,

I'm trying to simulatie a bobsled on a track. In this case the track is a looping.
Everything works and the plots are beautiful, but when I try to make a video of the plots, it fails. Matlab is making a video, but in the video you only see the first frame and you also see the Matlab editor slightly through it.

So my question is:
What causes the error that the video only takes the first frame, while matlab does the whole simulation (about 75 frames)?

My matlab code is:
%% Figure 1
nFrames = numel(x(:,1));
mov(1:nFrames) = struct('cdata', [],...
                        'colormap', []);
DELAY = 0.01;
figure('units','normalized','outerposition',[0 0 1 1]);
figure(1);
axis tight
set(gca,'nextplot','replacechildren');
for i = 1:numel(x(:,1))
    clf;
    x_coor=-0.75*pi:0.1:1.75*pi;
    y_coor=-pi/3:0.1:pi/3;
    [ff,gg]=meshgrid(x_coor,y_coor);
    x1 = (R+r.*cos(gg)).*cos(ff);
    z1 = (R+r.*cos(gg)).*sin(ff);
    y1 = r.*sin(gg)+k.*ff;
    surf(x1,y1,z1,'EdgeColor','blue','LineStyle',':','FaceLighting','gouraud');
    grid on;
    camlight
    view(-30,15);
    alpha(0.5);
    title('Looping','FontSize',14)
    xlabel('x')
    ylabel('y')
    zlabel('z')
    hold on;
    p = x(i,1);
    q = x(i,2);
    x2 =(R+r.*cos(q)).*cos(p);
    z2 =(R+r.*cos(q)).*sin(p);
    y2 =r.*sin(q)+k.*p;
    plot3(x2,y2,z2,'ro','LineWidth',2);
    mov(i) = getframe(gcf);
    pause(DELAY);
end
hold off
%movie(mov,1)
movie2avi(mov, 'looping.avi','FPS',10, 'compression','none','quality',100);

Short explanation of the plot:
At first, I solved a differential equation and the output is stored in the vector x. In the plot, I first plot the track (the looping) with 'surf' and after that the vector x (output of the ODE) with 'plot3' by using 'hold on'.

Thanx in advance!

Koos

Subject: Video, created with Matlab, shows only first frame during the whole video?!

From: Pavel

Date: 12 Jul, 2012 12:27:07

Message: 2 of 3

I have the similar problem. Matlab draws all frames but movie2avi saves only first 10 frames.
Can't resolve so far.

Subject: Video, created with Matlab, shows only first frame during the whole video?!

From: Summer Chan

Date: 18 Aug, 2012 10:16:07

Message: 3 of 3

I ever met a similar problem. And my OS is Windows7, there is something wrong with OpenGL Renderer. If you also use Windows7 or Vista, I think you can try this: set(gcf, 'Renderer', 'painters')
Put it under the figure code, it may fix the problem. Good luck!


"Koos" wrote in message <jrfseq$3jf$1@newscl01ah.mathworks.com>...
> Hello,
>
> I'm trying to simulatie a bobsled on a track. In this case the track is a looping.
> Everything works and the plots are beautiful, but when I try to make a video of the plots, it fails. Matlab is making a video, but in the video you only see the first frame and you also see the Matlab editor slightly through it.
>
> So my question is:
> What causes the error that the video only takes the first frame, while matlab does the whole simulation (about 75 frames)?
>
> My matlab code is:
> %% Figure 1
> nFrames = numel(x(:,1));
> mov(1:nFrames) = struct('cdata', [],...
> 'colormap', []);
> DELAY = 0.01;
> figure('units','normalized','outerposition',[0 0 1 1]);
> figure(1);
> axis tight
> set(gca,'nextplot','replacechildren');
> for i = 1:numel(x(:,1))
> clf;
> x_coor=-0.75*pi:0.1:1.75*pi;
> y_coor=-pi/3:0.1:pi/3;
> [ff,gg]=meshgrid(x_coor,y_coor);
> x1 = (R+r.*cos(gg)).*cos(ff);
> z1 = (R+r.*cos(gg)).*sin(ff);
> y1 = r.*sin(gg)+k.*ff;
> surf(x1,y1,z1,'EdgeColor','blue','LineStyle',':','FaceLighting','gouraud');
> grid on;
> camlight
> view(-30,15);
> alpha(0.5);
> title('Looping','FontSize',14)
> xlabel('x')
> ylabel('y')
> zlabel('z')
> hold on;
> p = x(i,1);
> q = x(i,2);
> x2 =(R+r.*cos(q)).*cos(p);
> z2 =(R+r.*cos(q)).*sin(p);
> y2 =r.*sin(q)+k.*p;
> plot3(x2,y2,z2,'ro','LineWidth',2);
> mov(i) = getframe(gcf);
> pause(DELAY);
> end
> hold off
> %movie(mov,1)
> movie2avi(mov, 'looping.avi','FPS',10, 'compression','none','quality',100);
>
> Short explanation of the plot:
> At first, I solved a differential equation and the output is stored in the vector x. In the plot, I first plot the track (the looping) with 'surf' and after that the vector x (output of the ODE) with 'plot3' by using 'hold on'.
>
> Thanx in advance!
>
> Koos

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
movie Koos 15 Jun, 2012 13:49:10
getframe Koos 15 Jun, 2012 13:49:10
rssFeed for this Thread

Contact us