surf colors with cylinder output

Hi, I have radius data for given depths. I'd like to plot it in 3D with colors matching the radius range. I'm not sure how to construct color palette correctly. r = 3.6247 3.6329 3.6412 3.6494; (r has over 8000 points) [x,y,z]=cylinder(r,10); surf(x,y,z). I can assign color with z surf(x,y,z,z) but I'm really after the visual change in radius. e.g red for radius lower than 3.63, yellow for 3.64 green for 3.65. (5 color ranges in total, or a color palette would be even better).
Below is 8000 radii used with z as color. I need to get the colors right, red where the radius is lowest of pipe's nominal ID.
Thank you!

 Respuesta aceptada

Mike Garrity
Mike Garrity el 26 de Mzo. de 2015
You're creating a lot of cylinders which each have a constant radius? If so, then something like this should work:
cla
hold on
for i=1:100
r = 1+rand(1);
[x,y,z] = cylinder(r,10);
surf(x,y,z+i,r*ones(size(z)),'EdgeColor','none');
end
view(3)
colorbar
What's going on there is that the 4th argument to surf is a CData array which is used for the face colors.
Of course, you could also combine them into a single surf, like this:
cla
hold off
x = [];
y = [];
z = [];
c = [];
for i=1:100
r = 1+rand(1);
[xt,yt,zt] = cylinder(r,10);
x(end+1,:) = xt(1,:);
y(end+1,:) = yt(1,:);
z(end+1,:) = i*ones(size(zt(1,:)));
c(end+1,:) = r*ones(size(zt(1,:)));
end
surf(x,y,z,c,'EdgeColor','none');

Más respuestas (0)

Productos

Preguntada:

el 26 de Mzo. de 2015

Comentada:

el 26 de Mzo. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by