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.

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 3 月 8 日

0 投票

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 件のコメント

Dominique
Dominique 2022 年 6 月 23 日
Ah! Ah! I made the same mistake.
Matthew Jenkins
Matthew Jenkins 2022 年 9 月 4 日
I did as well, thanks!

サインインしてコメントする。

カテゴリ

質問済み:

2018 年 3 月 8 日

コメント済み:

2022 年 9 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by