Can't save a video with VideoWrite: Error [Frame must be 550 by 420]

4 views (last 30 days)
% video traiettoria
v = VideoWriter('traiettoria');
open(v);%
figure
scatter(0,0,200,'r','filled','s');
hold on;
grid on, grid minor, axis equal;hold on;
title('traiettoria AUV in coordinate ne USBL');
xlabel('est (m)');hold on;
ylabel('nord (m)'); hold on;
curve = animatedline('Color','b','LineStyle','-','LineWidth',1);
for k = 1:length(t_raw_sec)
addpoints(curve,e_no_outliers(k),n_no_outliers(k))
drawnow;
frame = getframe(gcf);
writeVideo(v,frame);
end
close(v);
I can't save the video because the frames are not the same size, I suppose...any suggestion?Thanks!

Answers (1)

Image Analyst
Image Analyst on 4 May 2020
You need to set up the movie in advance so that all the frames are the same size. Here is a snippet you can modify.
% Set up the movie structure.
% Preallocate movie, which will be an array of structures.
% First get a cell array with all the frames.
allTheFrames = cell(numberOfFrames,1);
vidHeight = 344;
vidWidth = 446;
allTheFrames(:) = {zeros(vidHeight, vidWidth, 3, 'uint8')};
% Next get a cell array with all the colormaps.
allTheColorMaps = cell(numberOfFrames,1);
allTheColorMaps(:) = {zeros(256, 3)};
% Now combine these to make the array of structures.
myMovie = struct('cdata', allTheFrames, 'colormap', allTheColorMaps);
For a full demo, see my attached demo, movie_made_from_surf.m, where I make a movie out of a figure that I'm animating.

Categories

Find more on Animation 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!