Problem creating video mp4 from animation.

8 views (last 30 days)
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');

Accepted Answer

Bhaskar R
Bhaskar R on 14 Feb 2020
VideoWriter % correct one you have give videowriter(not case sensitive)
  3 Comments
Bhaskar R
Bhaskar R on 14 Feb 2020
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 on 14 Feb 2020
Thank you so much. The code has worked.

Sign in to comment.

More Answers (0)

Categories

Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!