How do I make a video plot with multiple line that appears as it plots?
7 views (last 30 days)
Show older comments
David Haydock
on 17 May 2023
Answered: Antoni Garcia-Herreros
on 17 May 2023
I have the following code:
writer_obj = VideoWriter('ms_GMD_video','MPEG-4');
open(writer_obj);
% parameters
x = 1:size(GMD,2);
ms_1 = GMD(1,x);
ms_2 = GMD(2,x);
ms_3 = GMD(3,x);
ms_4 = GMD(2,x);
ms_5 = GMD(5,x);
% create plotting figure
fig1 = figure(1);
% loop over all timepoints
for i = 1:length(x)
plot(x(i),ms_1(i))
hold on
plot(x(i),ms_2(i))
hold on
plot(x(i),ms_3(i))
hold on
plot(x(i),ms_4(i))
hold on
plot(x(i),ms_5(i))
hold on
axis([1 500 min(GMD,[],'all') max(GMD,[],'all')])
title('Dissimilarity Score')
F = getframe(fig1);
writeVideo(writer_obj, F);
end
close(writer_obj)
GMD is the input, and contains five lines that I would like to plot on a graph that changes over time.
I currently have it so that we only look at the first 500 time points as an example clip, which is fine.
But when I run this, there are no lines appearing on the graph.
Any help would be appreciated, thank you.
0 Comments
Accepted Answer
Antoni Garcia-Herreros
on 17 May 2023
Hello David,
It would be easier if you attached the the different variables (GMD, x, ms,...) as a .mat file.
The reason why the plot is not showing is because you are plotting single values with a LineStyle: '-'.
You could try something like this:
x=[0:0.1:pi];
writer_obj = VideoWriter('ms_GMD_video','MPEG-4');
open(writer_obj);
fig1=figure(1);
for i=2:length(x)
plot(x(i-1:i),sin(x(i-1:i)),'r')
hold on
plot(x(i-1:i),cos(x(i-1:i)),'b')
pause(0.1)
ylim([-1 1])
xlim([0 pi])
F = getframe(fig1);
writeVideo(writer_obj, F);
end
close(writer_obj)
0 Comments
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!