surf() function query, shading a 3d mesh plot.

5 次查看(过去 30 天)
Hi, Here is my code/graph that I want to shade in:
n=10;maxwidth=6;maxcolor=100;map=colormap(jet(maxcolor));
nelem=size(connectivity,1);
for ielem=1:nelem
nodei=connectivity(ielem,1);nodej=connectivity(ielem,2);
idof=ndof*(nodei-1)+1:ndof*(nodei-1)+ndof;jdof=ndof*(nodej-1)+1:ndof*(nodej-1)+ndof;
Xi=U(idof,1); Xj=U(jdof,1);
x=linspace(Xi(1),Xj(1),n);y=linspace(Xi(2),Xj(2),n);z=linspace(Xi(3),Xj(3),n);
width=A(ielem)/max(A)*maxwidth;
color=1+floor((N(ielem)-min(N))/(max(N)-min(N))*(maxcolor-1));
plot3(x,y,z,'LineWidth',width,'Color',map(color,:));
hold on;
end
grid on;
xlabel(['OX axis ' lengthunits]);ylabel(['OY axis ' lengthunits]); zlabel(['OZ axis ' lengthunits]);
caxis([min(N) max(N)]);colorbar('location','eastoutside');
title(['title ' units]);
How would I go about this? using the surf() function? Thanks.
  3 个评论
Jack
Jack 2015-5-1
Sorry about the lack of clarity before the code. I just would like to know how to 'fill in the gaps' of the graph if you will.
Thanks.

请先登录,再进行评论。

回答(1 个)

Chad Greene
Chad Greene 2015-5-1
Looks like surf will do what you want, but you'll need a X, Y, and Z as gridded 2D variables, not 1D arrays. I can't fully interpret your code, but it looks like you can easily convert your x and y linear arrays to grids with meshgrid. Here are six ways to display gridded variables. I'll use caps for gridded variables:
% linear arrays:
x = 1:50;
y = 301:350;
% gridded data:
[X,Y] = meshgrid(x,y);
Z = peaks(50);
subplot(231)
plot3(X,Y,Z)
title 'plot3'
subplot(232)
mesh(X,Y,Z)
title 'mesh'
subplot(233)
imagesc(x,y,Z)
axis xy
title 'imagesc'
subplot(234)
pcolor(X,Y,Z)
shading interp
title 'pcolor'
subplot(235)
surf(X,Y,Z)
title 'surf'
subplot(236)
surf(X,Y,Z)
shading interp
camlight
title 'surf+interp+camlight'

类别

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