I'm having my code here where I want to put animation. Can we show this animation wrt to any parameter?
MATLAB: How to make animtion of 3D surface plot
MATLAB
Related Solutions
The issue was with the resolution of the generated image. As the compression increases from AVI to MPEG-4, the quality drops.
You can see the AVI has better quality than MPEG-4.
v = VideoWriter('newfile.avi','Uncompressed AVI');% v = VideoWriter('newfile.mp4','MPEG-4');
% v.Quality = 100;
% v.FrameRate = 10;
This drop in quality due to increased compression needs to be compensated by increasing the resolution of the generated figures (or frames).\n
close all, clear allfigure('units','pixels','position',[0 0 1000 800]) % set figure's size
t = linspace(0,10,1000);y = randn(size(t));plot(t,y)hold onh_x = xline(t(1),'--r');v = VideoWriter('newfile.mp4', 'MPEG-4');v.Quality = 100;v.FrameRate = 10;open(v)for n = 1:length(t) h_x.Value = t(n); drawnow limitrate frame = getframe(gcf); f = imresize(frame.cdata,4); % resize the image
writeVideo(v,f);endclose(v)
Also, see this demo I made for another question http://www.mathworks.com/matlabcentral/answers/153962#answer_151015. Uncomment the stuff about videoWriter if you want to save the movie to disk.
clear all;clc;x=[-3:0.1:3];y=[-3:0.1:3];t=[0:0.1:5];hFigure = figure;numberOfFrames = length(t);% Set up the movie structure.
% Preallocate recalledMovie, 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);% Create a VideoWriter object to write the video out to a new, different file.
% writerObj = VideoWriter('problem_3.avi');
% open(writerObj);
% Need to change from the default renderer to zbuffer to get it to work right.
% openGL doesn't work and Painters is way too slow.
set(gcf, 'renderer', 'zbuffer'); [x, y] = meshgrid(-3:.1:3,-3:.1:3);for frameIndex = 1 : numberOfFrames z = exp(-(x-t(frameIndex)).^2-(y-t(frameIndex)).^2); cla reset; % Enlarge figure to full screen.
% set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
surf(x,y,z); axis('tight') zlim([0, 1]); caption = sprintf('Frame #%d of %d, t = %.1f', frameIndex, numberOfFrames, t(frameIndex)); title(caption, 'FontSize', 15); drawnow; thisFrame = getframe(gca); % Write this frame out to a new video file.
% writeVideo(writerObj, thisFrame);
myMovie(frameIndex) = thisFrame;end% close(writerObj);
message = sprintf('Done creating movie\nDo you want to play it?');button = questdlg(message, 'Continue?', 'Yes', 'No', 'Yes');drawnow; % Refresh screen to get rid of dialog box remnants.
close(hFigure);if strcmpi(button, 'No') return;endhFigure = figure;% Enlarge figure to full screen.% set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
title('Playing the movie we created', 'FontSize', 15);% Get rid of extra set of axes that it makes for some reason.
axis off;% Play the movie.
movie(myMovie);uiwait(helpdlg('Done with demo!'));close(hFigure);
Best Answer