MATLAB: Index in position 1 exceeds array bounds (must not exceed 1)

errorfor loop

Hi all, I'm not very good at MATLab and can't tell what is wrong or what this means, any help would be greatly appreciated.
Here is the code:
%Analytical
clc;
T = 200; %degrees C

D = 5E-3; %m

L = 50E-3; %m
T0 = 25; %degrees C
h = 100; %W/m^2 K
k = 393; %W/m^2 k
Ac = (pi/4)*(5E-3)^2;
P = pi*(5E-3);
m = sqrt((h*P)/(k*Ac));
Tx=zeros(5,1);
L3=(0:.0015:.05);
for n=1:length(L3)
Tx(n,1)= (cosh(m*(L-L3(n,1)))*(h/(m*k))*sinh(m*(L-L3(n,1)))/(cos(m*L)+(h/(m*k))*sinh(m*L)))*(T-T0)+(T0)
end
And here is the output
Tx =
28.9774
0
0
0
0
Index in position 1 exceeds array bounds (must not exceed 1).
Error in Analytical (line 16)
Tx(n,1)= (cosh(m*(L-L3(n,1)))*(h/(m*k))*sinh(m*(L-L3(n,1)))/(cos(m*L)+(h/(m*k))*sinh(m*L)))*(T-T0)+(T0)

Best Answer

Your L3 is of size 1*34. YOu used L3(n,1) which tried to access L3(2,1) which is not correct. Either you replace L3(n,1) with L3(n) or L3(1,n).
T = 200; %degrees C

D = 5E-3; %m

L = 50E-3; %m
T0 = 25; %degrees C
h = 100; %W/m^2 K
k = 393; %W/m^2 k
Ac = (pi/4)*(5E-3)^2;
P = pi*(5E-3);
m = sqrt((h*P)/(k*Ac));
Tx=zeros(5,1);
L3=(0:.0015:.05);
for n=1:length(L3)
Tx(n,1)= (cosh(m*(L-L3(n)))*(h/(m*k))*sinh(m*(L-L3(n)))/(cos(m*L)+(h/(m*k))*sinh(m*L)))*(T-T0)+(T0)
end