[X,Y,Z] = cylinder returns three
21 matrices containing the
x-, y-, and z-
coordinates of a cylinder without drawing it. The cylinder has a radius of 1 and
20 equally spaced points around its circumference. The bases are parallel to the
To draw the cylinder, pass
Z to the
[X,Y,Z] = cylinder( returns the
x-, y-, and z-
coordinates of a cylinder with the specified profile curve,
r, and 20 equally spaced points around its
circumference. The function treats each element in
r as a
radius at equally spaced heights along the unit height of the cylinder. The size
of each coordinate matrix is
m=numel(r). However, if
r is a
Display Unit Cylinder
Create and plot a cylinder with a radius equal to 1.
Specify Cylinder Radius and Height
Specify the radius of a cylinder by including the input
r. Then, specify the height of the cylinder by modifying the returned
Z as coordinates of a cylinder with a radius of 4.
r = 4; [X,Y,Z] = cylinder(r);
Specify a height of 20 by modifying the
Z coordinate. Plot the cylinder.
h = 20; Z = Z*h; surf(X,Y,Z)
Display Multiple Cylinders at Different Locations
Create a cylinder and use the returned coordinates to plot multiple cylinders in different locations.
Create a cylinder defined by the profile function
2 + cos(t).
t = 0:pi/10:2*pi; r = 2 + cos(t); [X,Y,Z] = cylinder(r);
Plot the cylinder with the base centered at the origin.
Plot two more cylinders on top of the first cylinder.
hold on surf(X,Y,Z+1) surf(X,Y,Z+2)
r — Profile curve
Profile curve, specified as a vector.
each element in
r as a radius at equally spaced heights
along the unit height of the cylinder.
n — Number of points
positive whole number
Number of points around the cylinder circumference, specified as a positive whole number.
ax — Target axes
Target axes, specified as an
Axes object. If you do not
specify the axes, then
cylinder plots into the current