3d plotting with MATLAB

In summary, to plot a 3D graph in MATLAB, you can use the "plot3" function and adjust the graph using other functions like "xlabel", "title", and "view". You can also plot multiple 3D graphs on the same figure by using the "hold on" command and creating subplots with the "subplot" function. To change the color or style of your graph, you can specify properties in the "plot3" function or use the "ColorOrder" property for multiple plots. Adding a legend is possible with the "legend" function and the "saveas" function can be used to save the graph as an image file with customizable properties.
  • #1
590
0
i am learning MATLAB, but have not yet learned anything do do with graphing, but need a program that can plot x.y.z graphs for my calculus work,

can someone please help me plot 3d graphs on MATLAB, for example

z=x2+2x+y2-y

how can i input x,y,z so that MATLAB will give me the surface graph of this function
 
Physics news on Phys.org

1. How do I plot a 3D graph in MATLAB?

To plot a 3D graph in MATLAB, you can use the "plot3" function. This function takes in three vectors representing the x, y, and z coordinates of your data points and plots them in 3D space. You can also add labels, titles, and adjust the viewing angle of the graph using other functions like "xlabel", "title", and "view".

2. Can I plot multiple 3D graphs on the same figure in MATLAB?

Yes, you can plot multiple 3D graphs on the same figure using the "hold on" command. This allows you to add new plots to an existing figure without erasing the previous ones. You can also use the "subplot" function to create a grid of subplots on a single figure.

3. How do I change the color or style of my 3D graph in MATLAB?

You can change the color or style of your 3D graph by specifying the "Color" and "LineStyle" properties in the "plot3" function. For example, you can use "plot3(x,y,z,'r--')" to plot a red dashed line. You can also use the "ColorOrder" property to change the default colors used for multiple plots.

4. Is it possible to add a legend to a 3D graph in MATLAB?

Yes, you can add a legend to a 3D graph in MATLAB by using the "legend" function. This function takes in a cell array of strings representing the labels for each plot, and it will automatically add a legend to your graph. You can also specify the location and other properties of the legend using additional arguments.

5. How do I save my 3D graph as an image file in MATLAB?

To save your 3D graph as an image file in MATLAB, you can use the "saveas" function. This function takes in the handle of your figure and the desired file format (e.g. 'png', 'jpg') as arguments. You can also adjust the resolution and other properties of the image using additional arguments.

Suggested for: 3d plotting with MATLAB

Replies
10
Views
877
Replies
5
Views
734
Replies
4
Views
978
Replies
3
Views
954
Replies
4
Views
1K
Back
Top