MATLAB: Draw a 3D model having x,y and z coordinates

MATLABmodel

Hello everyone i would like to know if you can help me with this question. I have an (6000×3) array, where the columns represents x,y and z coordinates of a point that when u link all of the points , they form a cylinder.
Is posible to create the model with those coordinates?

Best Answer

Your coordinates given are not forming a full cylinder. If you join them, you will not get a perfect cylinder as expected. As you said the points form a cyinder; I used the points to get radius and height of the cylinder, from this cylinder has been plotted.
data = xlsread("coordinates.xlsx") ;
x = data(:,1) ;
y = data(:,2) ;
z = data(:,3) ;
% Get radius of the Cylinder
Radius = mean(sqrt(x.^2+y.^2)) ;
% Center of cylinder
C = [0. 0.] ;
% Get height of the cylinder
Height = max(z) ;
% form cylinder
theta = 360. ; % Angle of the Cylinder
%
NH = 50 ; % Number of Elements on the Height
NT = 50 ; % Number of Angular Dicretisation
% Discretizing the Height and Angle of the cylinder
nH = linspace(0,Height,NH) ;
nT = linspace(0,theta,NT)*pi/180 ;
[H T] = meshgrid(nH,nT) ;
% Convert grid to cylindrical coordintes
X = Radius*cos(T);
Y = Radius*sin(T);
Z = H ;
surf(X,Y,Z)
hold on
plot3(x,y,z,'.k')
Related Question