Seal a cylinder in a scattered plot

1 回表示 (過去 30 日間)
Greek McCoy
Greek McCoy 2021 年 11 月 26 日
コメント済み: Les Beckham 2021 年 11 月 27 日
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.

採用された回答

Les Beckham
Les Beckham 2021 年 11 月 26 日
編集済み: Les Beckham 2021 年 11 月 26 日
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 件のコメント
Greek McCoy
Greek McCoy 2021 年 11 月 26 日
Hello Les Beckham,
Thank you very much for your answer.
My code works just as I want it now.
Les Beckham
Les Beckham 2021 年 11 月 27 日
You are quite welcome.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by