フィルターのクリア

User defined surface grid

35 ビュー (過去 30 日間)
Lars
Lars 2013 年 11 月 27 日
編集済み: Hannes Eschmann 2019 年 11 月 28 日
Hallo.
I am currently having troubles with defining a grid on the surface of my 3D plot (created by using mesh-function to plot with).
Would like to have something in between what's seen on the pictures below.
Wish to create following grid:
  • Horizontal lines (parallel with x-axis) for z = (0:1:10)
  • Vertical lines (parallel with z-axis) for x = (-10:2:10).
My code:
[X,Y] = meshgrid(-8:.1:8);
R = sqrt(X.^2 + Y.^2) + eps;
Z = sin(R)./R;
surf(X,Z,Y,Z)
set(gca,'YDir','Reverse','ZDir','Reverse')
colorbar; ylabel('y'); xlabel('x'); zlabel('z') ;
shading interp % To create right picture
What is the Matlab command for creating a surface grid as i wish?

採用された回答

Jeremy Wurbs
Jeremy Wurbs 2013 年 11 月 28 日
Ahh, I see. That is trickier. I get slightly better results by changing
mesh(XX,ZZ,YY,ZZ);
to
surf(XX,ZZ,YY,ZZ,'FaceAlpha',0)
although some of the edges are hidden still. If you're willing to cheat a little you can stick the edges out a tad bit:
surf(XX,ZZ+0.03,YY,ZZ,'FaceAlpha',0)
which seems to produce decent results.
  1 件のコメント
Lars
Lars 2013 年 11 月 29 日
Thank you so much for your help.

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

その他の回答 (2 件)

Jeremy Wurbs
Jeremy Wurbs 2013 年 11 月 27 日
編集済み: Jeremy Wurbs 2013 年 11 月 27 日
Great question. If I'm understanding correctly, you don't like the lines connecting your points to be so prevalent. You can fix this in your surf line:
surf(X,Z,Y,Z, 'EdgeAlpha', alpha)
Where alpha is some value between 0 and 1 (0.2 is probably good).
Hope that helps and is what you were looking for. Cheers.

Lars
Lars 2013 年 11 月 28 日
Thanks a lot for the answer so far. It improved a lot on the figure.
However it was not entirely what i was looking for. In the picture below i want a combination where i have the smoothness of the surface from the left picture but the gridlines from the right picture.
I tried with following code, where i create 3D plots in same figure, but can't get the "mesh" to be transparent.
[X,Y] = meshgrid(-8:0.1:8) ;
[XX,YY] = meshgrid(-8:1:8) ;
R = sqrt(X.^2 + Y.^2) + eps ;
Z = sin(R)./R ;
ZZ = (Z((1:10:size(Z)),(1:10:size(Z)))) ;
surf(X,Z,Y,Z,'EdgeAlpha', 0) ; hold on
mesh(XX,ZZ,YY,ZZ);
set(gca,'YDir','Reverse','ZDir','Reverse')
colorbar; ylabel('y'); xlabel('x'); zlabel('z') ;
The result is as following, which i don't like either:
  1 件のコメント
Hannes Eschmann
Hannes Eschmann 2019 年 11 月 28 日
編集済み: Hannes Eschmann 2019 年 11 月 28 日
an excessive way of archiving a smooth coarse grid, would be to just create it yourself, e.g., via
smoothMesh(X,Y,Z,10,'k',1,1)
where
function smoothMesh(X,Y,Z,delta,color,alp,w)
hold on
for i = 1:delta:size(X,1)
p = plot3(X(i,:),Y(i,:),Z(i,:),color,'LineWidth',w);
p.Color(4) = alp;
end
p = plot3(X(end,:),Y(end,:),Z(end,:),color,'LineWidth',w);
p.Color(4) = alp;
for i = 1:delta:size(X,2)
p = plot3(X(:,i),Y(:,i),Z(:,i),color,'LineWidth',w);
p.Color(4) = alp;
end
p = plot3(X(:,end),Y(:,end),Z(:,end),color,'LineWidth',w);
p.Color(4) = alp;

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

カテゴリ

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