Problem creating video mp4 from animation.

What's wrong with this code? Can you help me please?
%% Creating Video mp4 from Animation of a graph a point P(x,y) which is variable connected to three fixed point A(6,9),B(20,38),C(49,25).
clc
clear
close all
M=5000;
x=6:1:49; % x domain
y=9:1:38; % y domain
for i=1:length(x)
for j=1:length(y)
clf
L=sqrt((x(i)-6)^2+(y(j)-9)^2)+sqrt((x(i)-20)^2+(y(j)-38)^2)+sqrt((x(i)-49)^2+(y(j)-25)^2);
if L<M
M=L;
a=x(i);
b=y(j);
p = [6 20 49]; % x coordinates of three fixed points A, B, and C.
q = [9 38 25]; % y coordinates of three fixed points A, B, and C.
hold on;
grid on
title('Steiner minimal tree')
for n = 1:length(p)
plot([p(n) a],[q(n) b],'color',[0 0 1]);
myChar = char(64+n);
text(p(n)+1,q(n),myChar);
end
plot(p,q,'o','markerfacecolor','k','markeredgecolor','none', ...
'markersize',4);
plot(a,b,'o','markerfacecolor','r','markeredgecolor','none', ...
'markersize',8);
text(a+0.5,b+0.75,'P');
drawnow;
pause = .01;
F(i,j)= getframe(gcf);
end
end
end
mywriter = videowriter('Steiner minimal tree','MPEG-4');
mywriter.framerate = 60;
open(mywriter);
writevideo(mywriter,F);
close(mywriter);
Whwn I run this file command window shows
Cannot find an exact (case-sensitive) match for 'videowriter'
The closest match is: VideoWriter in F:\Matlab Alx\toolbox\matlab\audiovideo\@VideoWriter\VideoWriter.m
Error in animate_figure (line 37)
mywriter = videowriter('Steiner minimal tree','MPEG-4');

 采纳的回答

VideoWriter % correct one you have give videowriter(not case sensitive)

3 个评论

sorry i dont understand ? i am making video first time. thank you. Can you help me please?
This works for you
%% Creating Video mp4 from Animation of a graph a point P(x,y) which is variable connected to three fixed point A(6,9),B(20,38),C(49,25).
clc
clear
close all
M=5000;
x=6:1:49; % x domain
y=9:1:38; % y domain
mywriter = VideoWriter('Steiner minimal tree','MPEG-4');
% mywriter.framerate = 60;
mywriter.FrameRate = 60;
open(mywriter);
for i=1:length(x)
for j=1:length(y)
clf
L=sqrt((x(i)-6)^2+(y(j)-9)^2)+sqrt((x(i)-20)^2+(y(j)-38)^2)+sqrt((x(i)-49)^2+(y(j)-25)^2);
if L<M
M=L;
a=x(i);
b=y(j);
p = [6 20 49]; % x coordinates of three fixed points A, B, and C.
q = [9 38 25]; % y coordinates of three fixed points A, B, and C.
hold on;
grid on
title('Steiner minimal tree')
for n = 1:length(p)
plot([p(n) a],[q(n) b],'color',[0 0 1]);
myChar = char(64+n);
text(p(n)+1,q(n),myChar);
end
plot(p,q,'o','markerfacecolor','k','markeredgecolor','none', ...
'markersize',4);
plot(a,b,'o','markerfacecolor','r','markeredgecolor','none', ...
'markersize',8);
text(a+0.5,b+0.75,'P');
drawnow;
pause = .01;
% F(i,j)= getframe(gcf);
writeVideo(mywriter,getframe(gcf));
end
end
end
% mywriter = videowriter('Steiner minimal tree','MPEG-4');
% writevideo(mywriter,F);
close(mywriter);
Thank you so much. The code has worked.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Animation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by