Create avi with two different subplots
Show older comments
I have 100 files within the a folder called "test1" that I would like to create a movie from. However, each of these 100 files will either have a length of 360 or 720, and would like to plot them in different subplots while looping through the 100 files.
For example, for i = 1;
if length(file1) == 360 subplot(1,2,1)
elseif length(file1) == 720 subplot(1,2,2)
That way, I have a continuous movie that will either plot on one or the other.
The basic skeleton I have been using is this:
path1 = path/to/data;
dir1 = dir(path1);
vidya = VideoWriter('test.avi')
vidya.Framerate = 8;
open(vidya)
% Create initial image
subplot(1,2,1)
xaxis([0 360])
yaxis([0 100])
subplot(1,2,2)
xaxis([0 720])
yaxis([0 100])
for i = 3:length(dir1)
load(dir1(i).name)
if length(x) == 360
do stuff for this
subplot(1,2,1)
plot(x)
xaxis([0 360])
yaxis([0 100])
subplot(1,2,2)
xaxis([0 720])
yaxis([0 100])
frame = getframe(gcf)
writeVideo(vidya,frame)
clf
elseif length(x) == 720
do some stuff
subplot(1,2,1)
xaxis([0 360])
yaxis([0 100])
subplot(1,2,2)
plot(x)
xaxis([0 720])
yaxis([0 100])
frame = getframe(gcf)
writeVideo(vidya,frame)
clf
end
close(vidya)
For the sample dataset that I have, the first 80 files are such that length(x) == 360, and the data plots on the first subplot fine. However, when the 81st file has a length(x) == 720, nothing is plotted in the second subplot, and the first subplot goes blank. Any thoughts?
Answers (0)
Categories
Find more on Subplots 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!