How to add a cylinder to a scattered plot

8 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Chunru
Chunru il 26 Nov 2021
% 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 Commento
Greek McCoy
Greek McCoy il 26 Nov 2021
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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Discrete Data Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by