Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Video of stairs plot ?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have created videos of plots before !! But i wanted to know if I can use stairs() function for creating a video of subplots !!
My code is:
myVideo = VideoWriter('Final Comparison_ALC'); % open video file
myVideo.FrameRate = 250;
open(myVideo)
figure()
for k = 1:length(t_lqr)
subplot(3,1,1)
stairs(t_lqr(k),y_final(1,k));
hold on
grid on
grid minor
stairs(t_lqr(k),yhat(1,k));
xlabel(' Time (seconds)', 'interpreter', 'tex');
ylabel('y_1', 'interpreter', 'tex');
title('Output y_1', 'interpreter', 'tex');
legend('Actual y_1', 'Estimated y_1', 'Error');
xlim([0, max(t_lqr)]);
ylim([-0.6 0.6])
subplot(3,1,2)
stairs(t_lqr(k),y_final(2,k));
hold on
grid on
grid minor
addpoints(t_lqr(k),yhat(2,k));
xlabel('Time (seconds)', 'interpreter', 'tex');
ylabel('y_2', 'interpreter', 'tex');
title('Output y_2', 'interpreter', 'tex');
legend('Actual y_2', 'Estimated y_2', 'Error');
xlim([0, max(t_lqr)]);
ylim([-0.8 0.6])
subplot(3,1,3)
stairs(t_lqr, u_final);
hold on
grid on
grid minor
xlabel('Time (seconds)', 'interpreter', 'tex');
ylabel('Control', 'interpreter', 'tex');
title('Control Signal', 'interpreter', 'tex');
xlim([0, max(t_lqr)]);
ylim([0 0.2])
pause(0.1) % Pause and grab frame
frame = getframe(gcf); % get frame
writeVideo(myVideo, frame);
end
% In order to maximize the figure window in Windows
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
close(myVideo)
drawnow
I have attached the data as well just in case anyone wants to recreate. The plots should look something like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/295933/image.jpeg)
댓글 수: 0
답변 (0개)
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!