Seal a cylinder in a scattered plot
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Greek McCoy
el 26 de Nov. de 2021
Comentada: Les Beckham
el 27 de Nov. de 2021
Hello all,
I have a scattered plot superimposed with a cylinder.
I wish to seal the ends of the cylinder.
Below is my interial code:
% A = load ('Data.txt');
A = 0.05*rand(8, 4)
x = A (:,1 ) ;
y = A (:,2 ) ;
z = A (:,3 ) ;
Amplitude = A (:,4) ;
scatter3 (x , y, z, 30, Amplitude )
title ('Cylinderical Sample')
xlim ([-0.07 0.07])
ylim ([-0.09 0.09])
zlim ([0 0.10])
xlabel ('Breath /m')
ylabel ('Width /m')
zlabel ('Height /m')
pbaspect([1 1 2])
H = colorbar ;
ylabel (H, 'Amplitude')
hold on
r = 0.025;
[X,Y,Z] = cylinder(r);
surf (X,Y,Z, 'EdgeColor', 'none', 'FaceAlpha', 0.2);
Here are the results from the top view:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/814434/image.jpeg)
Is it possible that I can please get some assistance with sealing the ends of the cylinder?
Thank you.
0 comentarios
Respuesta aceptada
Les Beckham
el 26 de Nov. de 2021
Editada: Les Beckham
el 26 de Nov. de 2021
Try this (I'm skipping the scatter portion for this example and assuming that you want the 'caps' that seal the ends to have the same color as the cylinder).
First replace your last 3 lines with this
r = 0.025;
[X,Y,Z] = cylinder(r);
hsurf = surf (X,Y,Z, 'EdgeColor', 'none', 'FaceAlpha', 0.2); % capture the handle of the surf object
Then, to add the 'caps' on the end of the cylinder:
patch(X(1,:),Y(1,:),Z(1,:), hsurf.CData(1,:), 'FaceAlpha', 0.2)
patch(X(1,:),Y(1,:),Z(2,:), hsurf.CData(1,:), 'FaceAlpha', 0.2)
Add the 'EdgeColor', 'none' option if you don't want the edges of the 'caps' to show.
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!