How to add a cylinder to a scattered plot

조회 수: 8 (최근 30일)
Greek McCoy
Greek McCoy 2021년 11월 26일
댓글: Greek McCoy 2021년 11월 26일
Hello everyone,
I currently have a 3D data plot which I will like to superimpose with a cylinder.
Here is my current code:
%clear all;
%close all;
clc
A = load ('Data.txt');
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')
And results:
My challenge is that should i try to include a cylinder, I lose seeing the points in my scattered plot.
Here is the code I prepared to include the cylinder:
%clear all;
%close all;
clc
A = load ('Data.txt');
x = A (:,1 ) ;
y = A (:,2 ) ;
z = A (:,3 ) ;
Amplitude = A (:,4) ;
r = 0.025;
scatter3 (x , y, z, 30, Amplitude);
[X,Y,Z] = cylinder(r);
surf (X,Y,Z);
title ('Sample - VS 126')
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')
And here is how I have the results now:
Top View of Results:
Is it possible that I can get some assistance with including the cylinder into the scattered plot?
Thank you.
--
Greek

채택된 답변

Chunru
Chunru 2021년 11월 26일
% A = load ('Data.txt');
A = 0.05*rand(8, 4)
A = 8×4
0.0364 0.0250 0.0031 0.0097 0.0023 0.0306 0.0495 0.0304 0.0439 0.0292 0.0324 0.0319 0.0186 0.0394 0.0206 0.0185 0.0172 0.0416 0.0133 0.0249 0.0058 0.0326 0.0139 0.0158 0.0161 0.0404 0.0307 0.0112 0.0358 0.0139 0.0391 0.0407
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);
  댓글 수: 1
Greek McCoy
Greek McCoy 2021년 11월 26일
Hello Chunru,
Thank you very much for your brilliant input.
Your answer works perfectly.
Is there any way I can seal the top and bottom ends of the cylinder?
--
Sincerely,
Greek

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by