Seal a cylinder in a scattered plot
1 view (last 30 days)
Show older comments
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:
Is it possible that I can please get some assistance with sealing the ends of the cylinder?
Thank you.
0 Comments
Accepted Answer
Les Beckham
on 26 Nov 2021
Edited: Les Beckham
on 26 Nov 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 Comments
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D 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!