MATLAB: Adding 2d plot to 3d surface

In summary, to plot a straight line on the z=-200 plane of a 3d graph of a quadratic form using Matlab, you can use the contour3 function with the x and y data points and specify the z value as -200. This will draw the line along the z=-200 contour.
  • #1
gysush
26
0
Consider the 3d graph of a quadratic form: 1/2*trans(x)*A*x-trans(b)*x

Plot via matlab: surfc(X,Y,Z);

add following lines:
hold on
x=-10:10;
y=0.5*(2-3*x);
plot(x,y);

This plot a straight line which intersects the 3d surface. However, I wish for it be graphed on the contours: i.e. the 3d graph has contours where Z=-200. The plot(x,y) plots the straight line on the z=0 plane. I wish for it graph the straight line on the z=-200 plane.

I've considered doing a loops such that I graph single points for the z=-200 plane.

Thank you.
 
Physics news on Phys.org
  • #2
To plot the straight line on the z=-200 plane, you can use the contour3 function. This function will take the x and y data points as arguments and will draw a line along the z=-200 contour. For example:[X,Y,Z] = surfc(X,Y,Z);hold onx=-10:10;y=0.5*(2-3*x);contour3(X,Y,Z,[-200 -200],'r')plot(x,y);
 

Related to MATLAB: Adding 2d plot to 3d surface

What is MATLAB and how is it used?

MATLAB is a high-level programming language and interactive environment used for numerical computation, visualization, and programming. It is commonly used in scientific and engineering fields for data analysis, simulation, and modeling. MATLAB allows for the creation of 2D and 3D plots, as well as the combination of both types of plots on the same figure.

How can I add a 2D plot to a 3D surface in MATLAB?

To add a 2D plot to a 3D surface in MATLAB, you can use the pcolor or contour functions. These functions allow you to specify the X and Y coordinates for the 2D plot and the Z coordinates for the 3D surface. You can also customize the appearance of the plot and surface using various options and settings.

Can I overlay multiple 2D plots on a 3D surface in MATLAB?

Yes, you can overlay multiple 2D plots on a 3D surface in MATLAB. You can use the hold on command to plot multiple 2D plots on the same figure, and then use the surf or mesh function to add the 3D surface. You can also use the view function to change the angle and perspective of the 3D surface and plot.

What are some tips for creating a visually appealing 3D surface with 2D plots in MATLAB?

To create a visually appealing 3D surface with 2D plots in MATLAB, it is important to choose appropriate colors, labels, and titles for your figure. You can also adjust the lighting and shading of the 3D surface using the light and shading functions. Additionally, you can use the grid and axis functions to add grid lines and customize the axes of your figure.

Are there any limitations to adding 2D plots to 3D surfaces in MATLAB?

There are some limitations to adding 2D plots to 3D surfaces in MATLAB. For example, the pcolor and contour functions do not support transparency, so you cannot overlay a translucent 2D plot on a 3D surface. Additionally, the surf and mesh functions do not support plotting 2D data, so you cannot add a 2D plot directly onto a 3D surface created with these functions.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
436
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • General Math
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top