save graph in video

7 views (last 30 days)
Jonathan Demmer
Jonathan Demmer on 16 Mar 2021
Commented: Adam Danz on 17 Mar 2021
Hi all,
My supervisor gave me this code. I modified it to make it work like i wnated. However i would like at the end of the code to save the video that has been created. Does someone know how to do that?
Thank you for your help
clear all
close all
addpath C:\Matlab_download\m_map1.4f\
load ('October_01_2014_surface_lat_##.mat');
load ('October_01_2014_surface_lon_##.mat');
lat1 = lat(4187,:);
lon1 = lon(4187,:);
%day = M(a,2);
%month = M(a,3);
%year = M(a,4);
%hour = M(a,5);
%mins = M(a,6);
LNMIN = -5.8;%horizontal
LNMAX = -2.5;
LTMIN = 52.7; %vertical
LTMAX = 55;
m_gshhs_f('patch',[.7 .7 .7],'edgecolor',[.2 .2 .2]),hold all
m_grid('linestyle','none','box','fancy','tickdir','in','fontsize',11,'Fontname','Times New Roman');
set(gca,'tickdir','out','fontweight','bold','fontsize',15,'Fontname','Times New Roman');
% time step 1:
h1 = m_plot(X(1),Y(1),'.-b');
hold on
h2 = m_plot(X(1),Y(1),'or');
h3 = m_plot(X(1),Y(1),'^','color',[0 0.6 0],'linewidth',2);
for it=2:length(lat1)
lag = min([it,25]);
h1 = m_plot(X(it-lag+1:it),Y(it-lag+1:it),'.-b');
h2 = m_plot(X(it),Y(it),'or');
% work out date and display it....

Answers (2)

Image Analyst
Image Analyst on 17 Mar 2021
You can use exportgraphics() to save figures or axes. If you want an example of how to draw something in an axes and change it and make a movie out of it, check out my simple attached example.
  1 Comment
Jonathan Demmer
Jonathan Demmer on 17 Mar 2021
Wow!! That is amazing!! Thank you so much!!!

Sign in to comment.

Adam Danz
Adam Danz on 16 Mar 2021
Edited: Adam Danz on 17 Mar 2021
  1. Use F=getframe() to store an image of the plot for each iteration of the for-loop. Save F to file if you want to replay the movie without re-collecting the frames.
  2. Use movie(F,__) to play back the movie.
See Method 3: Create a movie for a demo.
Adam Danz
Adam Danz on 17 Mar 2021
You can use VideoWriter which is what ImageAnalyst is doing, I believe.
There's also a nice demo in the documentation,

Sign in to comment.


Find more on Startup and Shutdown 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!

Translated by