How to create a movie?

7 ビュー (過去 30 日間)
Rajawarman Thiruselvam
Rajawarman Thiruselvam 2021 年 7 月 8 日
回答済み: Bhavya Chopra 2021 年 7 月 8 日
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

採用された回答

Bhavya Chopra
Bhavya Chopra 2021 年 7 月 8 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by