MATLAB: When I plot this, the line isn’t showing up on the graph

graphsolid mechanics

diaCyl = 3
c = diaCyl / 2
for T = 0:5:50
tauMax = (T*c)/((pi/2)*(c^4))
plot(T,tauMax,'r-o'); hold on
title('Value of tau maximum for values of T');
xlabel('tau maximum');
ylabel('T');
end
But then my plot looks like this with no line

Best Answer

You need to save ‘tauMax’ a vector. Since ‘T’ does not have contiguous entries (the step increment is 5), it is best to create a different indexing variable to avoid gaps filled with zeros in the ‘tauMax’ vector.
Try this:
diaCyl = 3
c = diaCyl / 2;
Tv = 0:5:50;
for T = 1:numel(Tv)
tauMax(T) = (Tv(T)*c)/((pi/2)*(c^4));
end
plot(Tv,tauMax,'r-o')
title('Value of tau maximum for values of T')
xlabel('tau maximum')
ylabel('T')