Problem creating video mp4 from animation.

조회 수: 9 (최근 30일)
jakaria babar
jakaria babar 2020년 2월 14일
댓글: jakaria babar 2020년 2월 14일
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');

채택된 답변

Bhaskar R
Bhaskar R 2020년 2월 14일
VideoWriter % correct one you have give videowriter(not case sensitive)
  댓글 수: 3
Bhaskar R
Bhaskar R 2020년 2월 14일
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);
jakaria babar
jakaria babar 2020년 2월 14일
Thank you so much. The code has worked.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by