MATLAB: How to fix this error? Subscript indices must either be real positive integers or logicals.

error

Hi, I was trying to find my error in the code but I couldn't, anyone could help me with this??
This is my code, and in the line 77, when I try to run the code the following error is showed.
Subscript indices must either be real positive integers or logicals.
I was trying to find the error, I know is related with the names of the variables but I couldn't fix it.
MATLAB code
clc;clear all;close
T0=288;
P0=101325;
M0=1;
gamma_a=1.4;
gamma_g=1.335;
cp_a=1004.3;
cp_g=1150;
pi_c=25;
pi_fan=1.7;
T4t=1330+273;
eff_d=1;
eff_c=1;
eff_b=1;
eff_t=1;
eff_n=1;
eff_s=1;
pi_b=1;
cv_a=cp_a/gamma_a;
cv_g=cp_g/gamma_g;
R_a=cp_a-cv_a;
R_g=cp_g-cv_g;
delta_h=42*10^6;
BPR=5;
mtotal=400;
mcore=mtotal/BPR;
mfan=mtotal-mcore;
%Diffuser
T0t=T0*(1+((gamma_a-1)/2)*M0^2);
P0t=P0*(1+((gamma_a-1)/2)*M0^2)^(gamma_a/(gamma_a-1));
pi_d=(((eff_d*((gamma_a-1)/2*M0^2))+1)/(1+(gamma_a-1)/2*M0^2))^(gamma_a/(gamma_a-1));
%Compressor
T2t=T0t;
P2t=P0t*pi_d;
P3t=P2t*pi_c;
tau_c=((pi_c^((gamma_a-1)/gamma_a)-1)/eff_c)+1;
%Fan
T7t=T2t*pi_fan^((gamma_a-1)/gamma_a);
P7t=P2t*pi_fan;
%nozzle(fan);
T9t=T7t;
P9t=P7t;
P9=P0;
M9=sqrt(((P9t/P9)-1)/((gamma_a-1)/2));
Pcrit2=P9t*(1/((gamma_a+1)/2)^(gamma_a/(gamma_a-1)));
if Pcrit2 >= P0
M9=1;
T9=(T9t/(gamma_a+1)/2);
else
M9=sqrt(((P9t/P9)-1)/((gamma_a-1)/2));
T9=T9t/((1+((gamma_a+1)/2))*M8^2);
end
c9=sqrt(2*cp_a*(T9t-T9));
%Burner
T3t=T2t*tau_c;
P4t=P3t;
tau_b=T4t/T3t;
mfuel=(mcore*cp_a*T3t*(tau_b-1))/delta_h;
f=mfuel/mcore;
%Shaft
T5t=(T4t-((eff_s(cp_a*mcore*(T3t-T2t)+mfan*cp_a(T7t-T2t)))/(mcore+mfuel)*cp_g));
%Turbine
tau_t=T5t/T4t;
pi_t=(1-((1-tau_t)/eff_t))^(gamma_g/(gamma_g-1));
P5t=P4t*pi_t;
%nozzle(core)
%if the nozzle is ideal.
T8t=T5t;
P8t=P5t;
P8=P0;
M8=sqrt(((P8t/P8)-1)/((gamma_g-1)/2));
Pcrit=P8t*(1/((gamma_g+1)/2)^(gamma_g/(gamma_g-1)));
if Pcrit >= P0
M8=1;
T8=(T8t/(gamma_g+1)/2);
else
M8=sqrt(((P8t/P8)-1)/((gamma_g-1)/2));
T8=T8t/((1+((gamma_g+1)/2))*M8^2);
end
c8=sqrt(2*cp_g*(T8t-T8));

Best Answer

When accessing a variable, you cannot use fractional values or values <= 0 when used as variable indices. Matlab only accepts index values > 0 that are integers. In your code, this is giving the first error:
T5t=(T4t-((eff_s(cp_a*mcore*(T3t-T2t)+mfan*cp_a(T7t-T2t)))/(mcore+mfuel)*cp_g));
Matlab does not understand what these are:
cp_a(T7t-T2t) %ERROR
%T7t-T2t = 56.5761 and cp_a is a variable with value = 1.0043e+03.
%So, what is the 56.5761th term in cp_a???
eff_s(cp_a*mcore*(T3t-T2t)+mfan*cp_a(T7t-T2t)) %ERROR!
%eff_s = 1, so what is the nth index of 1???
Matlab index rules:
A = [1 2 3 4 5];
A(2) =
= 2
A(2.2) =
ERROR
Related Question