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

조회 수: 3 (최근 30일)
Jack
Jack 2015년 4월 30일
답변: Chad Greene 2015년 5월 1일
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일
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에서 Discrete Data Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by