MATLAB: How to make frame size same for subplots run in loop to make video using videowriter

videowriter

Hi friends,
I have written a code to make movie using videowriter command. But I am getting error.
close all
clear all
clc
theta=0:0.1:2*pi;
vidObj = VideoWriter('testMovie.avi');
open(vidObj);
for ii=1:100
ii
subplot(1,2,1)
plot(theta,sin(theta));
subplot(1,2,2)
plot(theta,cos(theta));
currFrame=getframe;
writeVideo(vidObj,currFrame);
close all
end
close(vidObj);
The error is saying frame is not matching with the previous figure.
Thanks in advance.

Best Answer

yes that can happen . plot() inside an axes can end up rendered slightly different sizes.
probably the easiest way to fix this is to imresize the result of getframe to a consistent size.
It is possible that you might notice the axes positions shifting slightly from frame to frame and it could even be the case that what should be the same curves move slightly depending upon the labels associated with the data. If you need the boxes to be exactly aligned frame to frame then you might need further precautions .