How to Improve Matlab's 3D Graphing Capabilities
Many researchers in engineering and the physical sciences use Matlab for data analysis and simulations. You may want to plot data in 3D to help with your analysis or for use in reports and presentations. Matlab's 3D graphing capabilities can be improved using some free downloads from MathWork's File Exchange community. "Export_fig" saves figures to many different formats and is more flexible and reliable than Matlab's built-in export function. "Vectline" allows you to plot 3D vector fields and "plot3c" creates 3D color-coded scatter plots, both of which cannot be made using Matlab's built-in functions.
Instructions
-
Exporting Figures
-
1
Download export_fig from the MathWorks File Exchange. Extract the contents of export_fig.zip to your Matlab path.
-
2
Open an existing 3D figure that you want to export.
-
-
3
Type "export_fig filename" in the Command window, where "filename" is replaced with the name you want to save your figure as. This will export your figure as it is displayed on the screen in encapsulated postscript format (EPS).
3D Vector Fields
-
4
Download the 3D/2D vector plotter from the MathWorks File Exchange. Then move the vectline.m file to your Matlab path.
-
5
Type "syms x y z; F = [x*y^3, x*y, z];" in the Command window. Replace "F = [x*y^3, x*y, z]" with your own field function, if you have one.
-
6
Type "vectline(F,[x,y,z],[-1,1,-2,3,1,3])" in the Command window to plot the 3D vector field. Replace "[-1,1,-2,3,1,3]" with the desired axis scale limits in the form "[xmin,xmax,ymin,ymax,zmin,zmax]."
3D Color-Coded Scatter Plots
-
7
Download plot3c from the Mathworks File Exchange. Then move the plot3c.m file to your Matlab path.
-
8
Load your data in the form of three independent variables: "x," "y" and "z" and one dependent variable "v" in the form of column vectors.
Type "x = rand(10,1); y = rand(10,1); z = rand(10,1); v = rand(10,1);" in the Command window if you do not have any data. This will generate some column vectors of random data.
-
9
Type "plot3c(x,y,z,v)" in the Command window to create your 3D color-coded scatter plot.
-
1
Tips & Warnings
Export_fig saves files in EPS by default. Type "open export_fig" in the Command window to see the other file formats available.
References
- Photo Credit Thinkstock Images/Comstock/Getty Images