Create Video of Rotating 3D Plot
Updated 3 Apr 2013
Captures a video of the 3D plot in the current axis as it rotates based on ViewZ and saves it as 'FileName.mpg'. Option can be specified.
ViewZ: N-rows with 2 columns, each row are the view angles in degrees, First column is azimuth (pan), Second is elevation (tilt) values outside of 0-360 wrap without error,
*If a duration is specified, angles are used as nodes and views are equally spaced between them (other interpolation could be implemented, if someone feels so ambitious).
*If only an initial and final view is given, and no duration, then the default is 100 frames.
FileName: Name of the file of the produced animation. Because I wrote the program, I get to pick my default of mpg-4, and the file extension .mpg will be appended, even if the filename includes another file extension. File is saved in the working directory.
(OptionZ): Optional input to specify parameters. The ones I use are given below. Feel free to add your own. Any or all fields can be used
OptionZ.FrameRate: Specify the frame rate of the final video (e.g. 30;)
OptionZ.Duration: Specify the length of video in seconds (overrides spacing of view angles) (e.g. 3.5;)
OptionZ.Periodic: Logical to indicate if the video should be periodic. Using this removed the final view so that when the video repeats the initial and final view are not the same. Avoids having to find the interval between view angles. (e.g. true;)
% % % Example (shown in published results, video attached) % % % %
MPEG-4 video option only available on Windows machines. See fix where the VideoWriter is called.
Getframe is used to capture image and current figure must be on monitor 1 if multiple displays are used. Does not work if no display is used.
Active windows that overlay the figure are captured in the movie. Set up the current figure prior to calling the function. If you don't specify properties, such as tick marks and aspect ratios, they will likely change with the rotation for an undesirable effect.
Cheers, Dr. Alan Jennings
Alan Jennings (2023). Create Video of Rotating 3D Plot (https://www.mathworks.com/matlabcentral/fileexchange/41093-create-video-of-rotating-3d-plot), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
- Image Processing and Computer Vision > Image Processing Toolbox > Geometric Transformation and Image Registration >
- MATLAB > Graphics > Formatting and Annotation > 3-D Scene Control > Lighting, Transparency, and Shading >
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.