Index in position 2 exceeds array bounds (must not exceed 2171).

1 view (last 30 days)
Dear members of this forum, ☺🙂🙏🏻😊
I hope and pray that you people will be good and happy....
I am receiving this error "Index in position 2 exceeds array bounds (must not exceed 2171)."... I append red-colored screenshot/snapshot of the received error and also the updated MATLAB code for convenience of the member who may become of help to me in this matter...
I scrolled through my MATLAB code several times but no success so far since few days...Therefore, I am posting here on this forum... Already I posted to one of my already going another query on this forum, MathWorks but response still awaited... Therefore, I had to post here also...
Relevant possible solution is requested... 😊😊🙂
Many thanks in advance
AllinOne14January2022V1
Index in position 2 exceeds array bounds. Index must not exceed 1865.

Error in AllinOne14January2022V1>nlcons (line 3762)
Ravailk = x(1,floor(Numtk+size(ttransij,2) + size(texeij,2)+ size(D_Cloud,2)+size(F_Cloud,2)+size(MuRSU,2)+... % "Ravail" keeps number of OBCU-mounted

Error in AllinOne14January2022V1>@(x)nlcons(x) (line 2463)
ncon = @(x)nlcons(x);

Error in barrier

Error in fmincon (line 862)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...

Error in AllinOne14January2022V1 (line 2486)
x = fmincon(fun, X0, A, b, Aeq, beq, lb, ub, ncon, options);

Accepted Answer

Cris LaPierre
Cris LaPierre on 31 Jan 2022
Edited: Cris LaPierre on 31 Jan 2022
I don't understand how you came up with the calculation for ravailk, but the sum of all the sizes is leading to a number greater than the total number of columns (position 2) in x.
The result of this calculation is 100000816 while the total number of columns in x is indicated in the top of the error message (1865 here, but it appears to change every run).
floor(Numtk+size(ttransij,2)+ size(texeij,2)+ size(D_Cloud,2)+size(F_Cloud,2)+...
size(MuRSU,2)+size(MaxNumtk,2)+size(E,2)+size(DPrc,2)+size(pc,2)+size(Muc,2)+...
size(Mui,2)+size(Muk,2)+size(B,2)+size(pi)+size(pm,2)+size(W,2)+size(Wfog,2)+...
size(t,2)+size(T,2)+size(cdk,2)+size(j,2)+size(i,2)+size(TasksperVehicle,2)+...
size(NTotal,2)+size(Numv,2)+size(Numtk,2)+size(TijPrime,2)+size(loop1,2)+...
size(Fprime,2)+size(PhikPrime,2)+size(D,2)+size(F,2)+Numv)
It is also interesting that the result is a 1x2 vector. It is probably supposed to be a scalar. You can fix that by replacing size(pi) with size(pi,2).

More Answers (0)

Community Treasure Hunt

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

Start Hunting!