Clear Filters
Clear Filters

Seal a cylinder in a scattered plot

2 views (last 30 days)
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)
A = 8×4
0.0349 0.0346 0.0168 0.0010 0.0342 0.0018 0.0060 0.0277 0.0224 0.0196 0.0081 0.0192 0.0382 0.0010 0.0373 0.0112 0.0053 0.0472 0.0435 0.0414 0.0169 0.0343 0.0157 0.0332 0.0256 0.0187 0.0223 0.0390 0.0488 0.0216 0.0233 0.0211
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.

Accepted Answer

Les Beckham
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
Greek McCoy
Greek McCoy on 26 Nov 2021
Hello Les Beckham,
Thank you very much for your answer.
My code works just as I want it now.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!