Error. Movie contains uninitialized frames

I'm trying to make a film with this code:
clc;
clear all;
m1= input('masa 1');
m2= input('masa 2');
L1= input('longitud 1');
L2= input('longitud 2');
g= input('gravedad');
Tfin= input('tiempo final');
DT= input('intervalo de momentos');
alpha= input('angulo alpha');
beta= input('angulo beta');
u= input('velocidad inicial');
%%Cálculos
%%1
NT= Tfin/DT;
C= linspace(0,Tfin,NT);
%%2
X1(1)= L1*sin(alpha);
Y1(1)= -L1*cos(alpha);
X2(1)= X1(1)+L2*sin(beta);
Y2(1)= Y1(1)-L2*cos(beta);
%%3
A= prepara_pend(m1,m2,L1,L2,g,DT);
%%4
V= transpose([alpha,beta,0,0]);
%%5
for J=2:NT
V= A*V;
alpha= V(1);
beta= V(2);
X1(J)= L1*sin(alpha);
Y1(J)= -L1*cos(alpha);
X2(J)= X1(J)+L2*sin(beta);
Y2(J)= Y1(J)-L2*cos(beta);
end
%%6
X=[X1,Y1];
Y=[X2,Y2];
plot(X1,Y1,'r',X2,Y2,'b')
grid on;
legend('X','Y');
%%opcional
for i=2:NT
M(i)=getframe;
end
movie(M)
but it gives me this error:
Error using movie
Movie contains uninitialized frames
how can I fix this?
Please some help, thanks.

Antworten (1)

Walter Roberson
Walter Roberson am 8 Mär. 2018

0 Stimmen

Where do you assign to M(1) ? You have
for i=2:NT
M(i)=getframe;
end
which starts creating M from M(2)
Note: it would be more efficient to initialize M(NT) to something first so that it would not be necessary to keep increasing the size of M as you ran the loop.
Also note that you are not giving any time for the frames to change, so you are going to be copying the same frame into the movie each time.

2 Kommentare

Dominique
Dominique am 23 Jun. 2022
Ah! Ah! I made the same mistake.
I did as well, thanks!

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 8 Mär. 2018

Kommentiert:

am 4 Sep. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by