User defined surface grid

14 次查看(过去 30 天)
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.

更多回答(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 CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by