MATLAB error: Subscript indices must either be real positive integers or logicals

1 回表示 (過去 30 日間)
AM
AM 2014 年 6 月 20 日
編集済み: Roger Stafford 2014 年 6 月 20 日
I have the following error in MATLAB, and it's driving me nuts! I have failed to fix it for 24 hours now, and I need your help.
Error using permute
ORDER contains an invalid permutation index.
Error in trapz (line 44)
y = permute(y,perm);
Error in HIVTBsolverDEqns_original (line 63)
HIVinf3=trapz(HIVinf1,HIVinf2)
This is my code:
global Lambda mu mu_H mu_T mu_IRIS beta tau lambda_H lambda_H_1 lambda_H_2 lambda_T lambda_T_1 lambda_T_2 gamma psi alpha
Lambda = 531062;
mu = 3.9138943e-5;
mu_H = 1.7809071e-4;
mu_T = 3.0398002e-4;
mu_IRIS = 4.8947959e-5;
beta = 4.6575342e-4;
tau = 1.0958904e-2;
lambda_H = 1;
lambda_H_1 = 0;
lambda_H_2 = 1-lambda_H_1;
lambda_T = 1;
lambda_T_1 = 1.6666667e-2;
lambda_T_2 = (lambda_T_1)./(180.*lambda_T_1-1);
gamma = 2.7528463e-4;
psi = 0.15;
alpha = 50;
%%%== Initial conditions ==
X_SS_0 = 192941151;
X_ST_0 = 132478723;
X_HS_0 = 2422951;
X_HT_0 = 1817998;
X_S_T_T_1_0 = 161501;
X_S_T_T_2_0 = 161501;
X_S_T_T_3_0 = 145865;
X_H_T_T_3_0 = 117;
X_H_T_T_1_0 = 7953;
X_H_T_T_2_0 = 7953;
X_H_T_T_T_1_0 = 3445;
X_H_T_T_T_2_0 = 3445;
X_H_T_1_0 = 3032;
X_H_T_2_0 = 152450;
X_H_T_T_T_IRIS_0 = 82;
y0 = [X_SS_0, X_ST_0, X_HS_0, X_HT_0, X_S_T_T_1_0, X_S_T_T_2_0, X_S_T_T_3_0, X_H_T_T_3_0, X_H_T_T_1_0, X_H_T_T_2_0, X_H_T_T_T_1_0, X_H_T_T_T_2_0, X_H_T_1_0, X_H_T_2_0, X_H_T_T_T_IRIS_0];
[t,y] = ode45('HIVTBEqns',[0:1:500],y0);
X_SS = y(1);
X_ST = y(2);
X_HS = y(3);
X_HT = y(4);
X_S_T_T_1 = y(5);
X_S_T_T_2 = y(6);
X_S_T_T_3 = y(7);
X_H_T_T_3 = y(8);
X_H_T_T_1 = y(9);
X_H_T_T_2 = y(10);
X_H_T_T_T_1 = y(11);
X_H_T_T_T_2 = y(12);
X_H_T_1 = y(13);
X_H_T_2 = y(14);
X_H_T_T_T_IRIS = y(15);
N = X_SS + X_ST + X_HS + X_HT + X_S_T_T_1 + X_S_T_T_2 + X_S_T_T_3 + X_H_T_T_3 + X_H_T_T_1 + X_H_T_T_2 + X_H_T_T_T_1 + X_H_T_T_T_2 + X_H_T_1 + X_H_T_2 + X_H_T_T_T_IRIS;
HIVinf1=0.1*[0:1:(length(X_SS)-1)];
HIVinf2=[(X_S_T_T_1+X_S_T_T_2).*(X_HS+X_HT+X_H_T_T_1+X_H_T_T_2+X_H_T_T_3)./N];
HIVinf3=trapz(HIVinf1,HIVinf2)
IRIScases1=0.1*[0:1:(length(X_H_T_T_T_1)-1)];
IRIScases2=[gamma.*(X_H_T_T_T_1+(1/178).*(179-1/lambda_T_1).*(X_H_T_T_T_2))];
IRIScases3=trapz(IRIScases1,IRIScases2)
IRISdeaths1=0.1*[0:1:(length(X_H_T_T_T_IRIS)-1)];
IRISdeaths2=[mu_IRIS.*(X_H_T_T_T_IRIS)];
IRISdeaths3=trapz(IRISdeaths1,IRISdeaths2)
AIDSdeaths1=0.1*[0:1:(length(X_H_T_T_1)-1)];
AIDSdeaths2=[mu_H.*(X_H_T_T_1+X_H_T_T_2)];
AIDSdeaths3=trapz(AIDSdeaths1,AIDSdeaths2)
I can't see what's wrong with the HIVinf3 line, or any other line for that matter! I have been using very similar code for a long time, with no problems. I don't know why this is happening.
I have tried removing the subscripts from X_SS_0 and X_ST_0 etc. but it didn't do anything. I have tried writing HIVinf3=trapz(HIVinf1,HIVinf2,1) - but it just gives me 0.
My HIVTBEqns file is working fine - let me know if you want to see it. It is not long.
Thanks for any help.

採用された回答

Roger Stafford
Roger Stafford 2014 年 6 月 20 日
編集済み: Roger Stafford 2014 年 6 月 20 日
As you have defined X_SS it is a single scalar quantity: X_SS = y(1). Consequently length(X_SS)-1 is 0 and therefore HIVinf1 will consist of the single number 0. I doubt if that makes 'trapz' very happy. The same trouble seems to occur with 'IRIScases1' and 'IRISdeaths1'.
  1 件のコメント
AM
AM 2014 年 6 月 20 日
Thank you very much sir. I didn't realize the error until you pointed me to the fact that it should say `y(:,1)`, `y(:,2)`, etc.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by