MATLAB: Simplifying code for plot.

MATLABplot

How simplify my code to where I can write t=[0 .2 .5 1 2] instead of writing them individually as t1,t2 etc… And possibly plot it as just plot(x,y) to where I get the same graph. Below is the code I am referring to.
clear
t0=0
t1=.2
t2=.5
t3=1
t4=2
x=-6:12/100:6
y0=-2*sinh(x)./(cosh(x)-exp(-t0));
y1=-2*sinh(x)./(cosh(x)-exp(-t1));
y2=-2*sinh(x)./(cosh(x)-exp(-t2));
y3=-2*sinh(x)./(cosh(x)-exp(-t3));
y4=-2*sinh(x)./(cosh(x)-exp(-t4));
plot(x,y0,'--')
hold on
plot(x,y1)
plot(x,y2)
plot(x,y3)
plot(x,y4)
axis([-6 6 -4 4])

Best Answer

This works:
tv = [0 .2 .5 1 2];
x = -6:12/100:6;
for k1 = 1:length(tv)
y(k1,:) = -2*sinh(x)./(cosh(x)-exp(-tv(k1)));
end
figure(1)
plot(x, y)
grid
axis([xlim -4 4])
legend('t = 0.0', 't = 0.2', 't = 0.5', 't = 1.0', 't = 2.0')
With a ‘t’ vector of only 5 elements, it’s easier to to just use a loop and some straightforward coding. With a longer vector, other approaches (using bsxfun and parsing the legend entries) would be more efficient.