MATLAB: Index exceeds matrix dimensions (Thermal 1d model)

dimensionserrorindex

I'm trying to write a 1D thermal model using a finite difference scheme. I'm still an amateur programmer so I apologize for my ignorance. I keep getting this error: Index exceeds matrix dimensions. I know this means that I'm trying to access an element in an array using an index that exceeds the dimension of the array but I don't know what to do with that information.
N = 15;
% Geometrically increasing grid spacing
z = 0;
zs = [kappa*P/pi]^(1/2);
deltaz = zs/10;
for i = 1:N
deltaz(i+1) = deltaz(i)*(1+1/5);
z(i+1) = z(i)+deltaz(i);
T0 = [[(S0/R^2).*(1-A)]/(e*(5.67*10^-8))]^(1/4);
TN = T0/((2)^(1/2));
T(i+1) = TN - (TN-T0)*exp(-z(i+1)/0.06);
zor(i+1) = deltaz(i+1)*deltaz(i)*(deltaz(i+1)+deltaz(i));
alpha_model(i+1) = 2*K*deltaz(i+1)/zor(i+1);
beta_model(i+1) = 2*K*deltaz(i)/(zor(i+1));
for n= 1:N
T(i+1,n+2) = T(i+1,n+1) + [dt/(rho*cp)].*[alpha_model(i+1).*T(i,n+1)-(alpha_model(i+1) + beta_model(i+1)).*T(i+1,n+1) + beta_model(i+1).*T(i+2,n+1)];
end
end

Best Answer

You define
T(i+1) = TN - (TN-T0)*exp(-z(i+1)/0.06);
but access
T(i+1, n+1)