アニメーションをAVIファイルなどのビデオファイルに保存するためには、VideoWriter
オブジェクトを使用します。コード1のスクリプトは、第3項の「運動する点のアニメーション」をAVIファイルに保存します。望ましい結果を得るためには、時間刻み(Time data)や VideoWriter
オブジェクトのプロパティ値を調整する必要があります。
% animation_point_videowriter.m clear; close all; % Create motion data t = 0:0.005:1; % Time data x = sin(2*pi*t); % Position data % Draw initial figure figure(1); h = plot(x(1), 0, 'o', 'MarkerSize', 20, 'MarkerFaceColor', 'b'); xlim([-1.5,1.5]); ylim([-1.5,1.5]); % Create & open video writer vw = VideoWriter('animation_point.avi'); vw.Quality = 100; vw.FrameRate = 60; open(vw); % Animation loop for i = 1:length(x) set(h, 'XData', x(i)); drawnow; % Write each frame to video frame = getframe(gcf); writeVideo(vw, frame); end % Close video writer close(vw);