Seal a cylinder in a scattered plot
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!