surf() function query, shading a 3d mesh plot.
3 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Chad Greene
on 1 May 2015
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'

0 Comments
See Also
Categories
Find more on Discrete Data Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!