MATLAB: How to draw a series of rotated cylinders in a row

cylinderfigureplotrotatesurf

Hi, I'm trying to make a cylinder made out of cylinders (meaning that it is segmented) so that i can show the transfer of heat in time, which means that every cylinder must have a certain color. The cylinder is supposed to look like this one:
The code i've made is the following:
figure('Name','JT Kick Simulation','NumberTitle','off');
hold on
c=gobjects(1,100);
for i=1:100
[c1X,c1Y,c1Z] = cylinder;
c(i)=surf(radiusbottom*(c1X),radiusbottom*(c1Y),heightbottom*(c1Z)+i,'FaceColor',[0 0 1],'EdgeColor','k');
rotate(c(i), [0 1 0], 90)
end
But when I run it, the cylinders are all out of place. I've tried changing the value that is increased in the loop but it doesn't work, does anybody knows what can I do?
Thanks.

Best Answer

YOu may try something like this:
% Units are considered in MKS system
Radius = 0.1 ; % Radius of the cylindrical shell
theta = 360. ; % Angle of the Cylinder
Height = 50. ; % Height of the Cylinder
%--------------------------------------------------------------------------
% Number of points (nodes) on the Height and Angluar discretization
npH = 100 ;
npT = 100 ;
nnode = npH*npT ; % Number of nodes
% Discretizing the Height and Angle of the cylinder
nH = linspace(0,Height,npH) ;
nT = linspace(0,theta,npT)*pi/180 ;
[H, T] = meshgrid(nH,nT) ;
% Convert grid to cylindrical coordintes
YY = Radius*cos(T);
ZZ = Radius*sin(T);
XX = H ;
surf(XX,YY,ZZ) ;
shading interp