How do I add a 2D Plot along with a surface or mesh plot in MATLAB?

29 ビュー (過去 30 日間)
Bharath Lohray
Bharath Lohray 2013 年 4 月 30 日
I would like to have a 2D plot along with a 3D surface or mesh plot - shown by the blue line I drew on the surface plot below. How do I get it?
  2 件のコメント
Bharath Lohray
Bharath Lohray 2013 年 5 月 1 日
Kye's Solution works. But it shrinks my plot to a ceiling surface. Is there a way to plot with 2 Y axis? The continuing question - http://www.mathworks.com/matlabcentral/answers/74232-how-do-i-add-2-y-axis-to-my-matlab-plot

サインインしてコメントする。

採用された回答

Kye Taylor
Kye Taylor 2013 年 5 月 1 日
Does this get you started?
% create figure
figure
% Generate data to make a surface
x = -1:0.1:1;
y = -1:0.1:1;
[X,Y] = meshgrid(x,y);
Z = X.^2 + Y.^2 - 1;
% visualize 3D surface
surf(X,Y,Z)
% Generate data to make line plot in plane z = minimumZValue
minimumZValue = min(Z(:));
t0 = linspace(0,2*pi);
x0 = .8*cos(t0);
y0 = .8*sin(t0);
% visualize line plot
line(x0,y0,minimumZValue*ones(size(t0)),'linewidth',2)
% Generate data to make line plot in plane x = minimumXValue
minimumXValue = min(X(:));
y00 = linspace(min(Y(:)),max(Y(:)));
% will be shifted to make z = minimumZValue the new z = 0
z00 = exp(-5*y00.^2);
z00 = z00 + minimumZValue; % comment this out to see effect
line(minimumXValue(ones(size(y00))),y00,z00,'linewidth',2,'color','r')
xlabel('x')
ylabel('y')
grid on
view(3)
  2 件のコメント
Walter Roberson
Walter Roberson 2013 年 5 月 1 日
Notice that Kye has used a 3-dimensional line rather than a 2-dimensional one. The equivalent higher-level routine would be plot3().
If you attempt to put a 2 dimensional plot in with a 3 dimensional plot, then although you might be able to get it to work with a specific view, it would stop working if you rotated the view at all.
Bharath Lohray
Bharath Lohray 2013 年 5 月 1 日
Hi, It works on being rotated as well - unless the answer got edited after your comment.
I got it to work, but My data had two different ranges. This shrinks my plot to a ceiling surface. Is there a way to plot with 2 Y axis? The continuing http://www.mathworks.com/matlabcentral/answers/74232-how-do-i-add-2-y-axis-to-my-matlab-plot

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by