4.75

4.8 | 5 ratings Rate this file 119 Downloads (last 30 days) File Size: 810 KB File ID: #41093
image thumbnail

Create Video of Rotating 3D Plot

by

 

Specify a set of view angles and this function creates a video for use in presentations.

| Watch this File

File Information
Description

CaptureFigVid(ViewZ, FileName,OptionZ)
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) % % % %
figure(171);clf;
surf(peaks,'EdgeColor','none','FaceColor','interp','FaceLighting','phong')
daspect([1,1,.3]);axis tight;
OptionZ.FrameRate=15;OptionZ.Duration=5.5;OptionZ.Periodic=true;
CaptureFigVid([-20,10;-110,10;-190,80;-290,10;-380,10], 'WellMadeVid',OptionZ)

Known issues:
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

Required Products MATLAB
MATLAB release MATLAB 7.14 (R2012a)
Other requirements Windows OS (for default mpg video format, or Mac with MATLAB 2013a and later) Monitor
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
14 Aug 2014 Casey  
20 May 2014 Lazaros Moysis

Thanks for your reply! that helped me for sure! Changing the rating to 5.

19 May 2014 Alan Jennings

Glad it helped Lazaros!
To make it bigger, just make the figure window bigger.
If you’re having issues with the compressions with the ‘MPEG’ format, you can add a quality factor, but the default of 75 (of 100) normally works good for me.
Add the following lines to the function, CaptureFigVid.m
Line 72:
if isfield(OptionZ,'Quality')
daObj.Quality=OptionZ.Quality;
end
And then from where you call it, add
OptionZ.Quality=100;

16 May 2014 Lazaros Moysis

Can you specify the size of the video to upgrade the quality and make it better looking?

11 Mar 2014 Lilian

Hi,

Can you help me transform this function
function Graf1()
x=(-2:0.08:2);
y=(-2:0.08:2);
a=2;
b=2;
for i = 1:length(x)
for j = 1:length(y)
if (a*abs(x(i))) <= abs(y(j))
z(i,j) = abs(y(j))
end
if (( abs(x(i)) <= abs(y(j)) ) && ( abs(y(j)) <= a*abs(x(i))))
z(i,j) = a*abs(x(i));
end
if (b*abs(y(j))) <= abs(x(i))
z(i,j) = abs(x(i))
end
if (( abs(y(j)) <= abs(x(i)) ) && ( abs(x(i)) <= b*abs(y(j))))
z(i,j) = b*abs(y(j))
end

end

end

surfc(z)
title ('Plot Title', 'FontWeight','Bold','FontSize',11) % Add labels...
xlabel ('X Axis Label', 'FontWeight','Bold','FontSize',11)
ylabel ('Y Axis Label', 'FontWeight','Bold','FontSize',11)
zlabel ('Z Axis Label', 'FontWeight','Bold','FontSize',11)
grid on ; % Switch on the figure grid, and
set(gca,'GridLineStyle','-') % set the grid to solid li
end

I do not understand how can I rotate my graph drawing function.

Thank you !!! :)

04 Sep 2013 Christian Jensen

If I don't include (...,'FaceLighting','phong')
in my surf plot, the figure spins but the movie is just one static image. Why is that?

04 Apr 2013 arnold

Thanks! A couple of bugs/ideas:

1. You should make it an option to fix the "zoom pumping", maybe it is the camera position, that rotation the plot under a larger elevation (say 45°) does not cause the plot to zoom in and out in every quadrant while rotating. Try this to see what I mean:

CaptureFigVid([0,45;-359,45], 'WellMadeVid',OptionZ)

Just as an example, this file solves this quite nicely
http://www.mathworks.com/matlabcentral/fileexchange/40572-spinrotate-your-plot

2. spacing the view angles makes sense, but I don't get why I can only specify two view angle pairs. In line 89 you limit this. Why not make it dependent on OptionZ.Periodic?

3. OptionZ.Periodic=true still causes a non-smooth jump when looping the video. Don't know why this is exactly

4. Add export for an animated gif instead of mp4. How to write one can be seen here:
http://www.mathworks.com/matlabcentral/fileexchange/21944-animated-gif

Contact us