User defined surface grid
46 次查看(过去 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?
0 个评论
采纳的回答
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
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.
0 个评论
Lars
2013-11-28
1 个评论
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 Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!