How to create a movie?

6 Ansichten (letzte 30 Tage)
Rajawarman Thiruselvam
Rajawarman Thiruselvam am 8 Jul. 2021
Beantwortet: Bhavya Chopra am 8 Jul. 2021
Hi everyone!! i have a code for animated line, here how to create a movie for this program??
clear all
close all
clc
figure
h1=animatedline('linewidth',3,'color','[0 0 0.5]');
h2=animatedline('linewidth',3,'color','[1 0.5 0]');
axis([0 71 1 20])
axis ij
grid on
x1 =0:71;
n=100;
xx1=linspace(x1(1),x1(end),n);
y1=[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1];
yy1=interp1(x1,y1,xx1);
y2=[2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3];
yy2=interp1(x1,y2,xx1);
for ci=1:n
addpoints(h1,xx1(ci),yy1(ci));
addpoints(h2,xx1(ci),yy2(ci));
pause(0.05);
drawnow
end

Akzeptierte Antwort

Bhavya Chopra
Bhavya Chopra am 8 Jul. 2021
I understand that you want to save your animated plot as a video. The program can be modified as follows to save the plot:
outputVideo = VideoWriter(fullfile(pwd, 'plot_movie.avi')); % Create VideoWriter object
outputVideo.FrameRate = 20; % Set frame rate for corresponding pause duration
open(outputVideo)
for ci=1:n
addpoints(h1,xx1(ci),yy1(ci));
addpoints(h2,xx1(ci),yy2(ci));
pause(0.05);
drawnow
img = getframe % Obtain figure as movie frame
writeVideo(outputVideo, img); % Write image to video
end
close(outputVideo) % Close video file
Please refer to documentation for getframe function and VideoWriter for more information.

Weitere Antworten (0)

Kategorien

Mehr zu Animation finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by