How to make frame size same for subplots run in loop to make video using videowriter?
10 views (last 30 days)
Show older comments
Raj Kishor
on 24 Feb 2019
Commented: Walter Roberson
on 25 Feb 2019
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.
0 Comments
Accepted Answer
Walter Roberson
on 24 Feb 2019
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 .
4 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!