Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

Video of stairs plot ?

1 view (last 30 days)
Japnit Sethi
Japnit Sethi on 20 May 2020
Closed: MATLAB Answer Bot on 20 Aug 2021
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:

Answers (0)

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!