what is the meaning of index exceeds array bound

댓글 수: 3

clc
clear
%Step 1: Define decision variables
x =optimvar('x',2,'LowerBound',[0 0],'UpperBound',[5 5]);
%Step 2: Define objective function
obj = x(1)^2 + x(2)^2 + x(3)^2;
%Step 3: Define constraints (if any)
A = 1 -x(2)^(-1)* x(3) >= 0;
B = x(1) - x(3) >=0;
C = x(1) - x(2)^2+x(2)*x(3)-4 ==0;
%Step 4: Define objective problem
prob = optimproblem('Objective',obj,'ObjectiveSense','maximize');
prob.Constraints.con_1 = A;
prob.Constraints.con_2 = B;
prob.Constraints.con_2 = C;
%Step 5: Solve the problem
x0.x = [0 0];
%Defining initial starting point
[sol, fval, exitflag, output] = solve(prob,x0);
suman sourabh
suman sourabh 2022년 3월 27일
kindly resolve this
You have
x =optimvar('x',2,'LowerBound',[0 0],'UpperBound',[5 5]);
so you say that x is a vector of 2 optimization variables. Your upper bound and lower bound are both vectors of length 2, which is consistent. x is not ambiguous: it really is length 2.
obj = x(1)^2 + x(2)^2 + x(3)^2;
but there you try to use x(3)^2 which would require that x be of length 3 or more.
Your constaints A, B, C all require that x has at least 3 elements.
x0.x = [0 0];
but that says that the initial value is a vector of length 2.
You need to decide whether your function involves 2 variables or 3 variables.

댓글을 달려면 로그인하십시오.

 채택된 답변

madhan ravi
madhan ravi 2018년 9월 2일
편집: madhan ravi 2018년 9월 2일

3 개 추천

It means that the index number is more than the array elements.
An example:
x=[1:10]
x(11)
Your array has 10 elements but you try accessing the 11th element.

댓글 수: 9

Walter Roberson
Walter Roberson 2018년 9월 2일
For example, if you have a vector with 5 elements in it, and you ask to return the 6th element, then the 6 would be out of bounds in that case.
madhan ravi
madhan ravi 2018년 9월 2일
@Chaitanya lakeshri please let us know if something is unclear.
Chaitanya Lakeshri
Chaitanya Lakeshri 2018년 9월 5일
Got it Thank you for your
Chaitanya Lakeshri
Chaitanya Lakeshri 2018년 9월 5일
Got it Thank you for your help Madhan and walter
madhan ravi
madhan ravi 2018년 9월 5일
Your welcome :)
Sir if we are using like in the latest version, idx=1 and filename = files(idx);
the error occurs like this "Index exceeds array bounds."
here i used the same example and code from
openExample('nnet/ClassifyVideosUsingDeepLearningExample')
Walter Roberson
Walter Roberson 2019년 3월 28일
hmdb51Files() returned empty for you.
I suspect that you are not running R2019a .
Umar Farooq
Umar Farooq 2022년 11월 28일
Erro
Index in position 1 exceeds array bounds. Index must not exceed 1.
Error in New_Arya_Paris (line 27)
RI(i,j)=(di(i,j)+ di(i+1,j))/4000;
-------------------------------------------------------
Problm
w=[1.000 0.993 0.984 0.968 0.938 0.870 0.787 0.766 0.660 0.553 0.383 0.298 0.234 0.191 0.085]
d=[2.000 1.000 0.500 0.250 0.150 0.053 0.054 0.039 0.023 0.013 0.008 0.006 0.005 0.004 0.001]
di=d.*100
wi=(w.*1000)
ni=15
for j=1:1;
for i=1:(ni-1)
RI(i,j)=(di(i,j)+ di(i+1,j))/4000;
end
end
Walter Roberson
Walter Roberson 2022년 11월 28일
You create a row vector, 1 row multiple columns. but index it as multiple rows with one column.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

CECILIA ABASCAL FALAGAN
CECILIA ABASCAL FALAGAN 2020년 8월 16일

0 개 추천

Good morning,
I would like to obtain the real time of my computer to later carry out operations and obtain the elapsed time. I have used the "datetime" command but I can't separate the time from the date and use it for this purpose. Any suggestion? I would be very grateful

댓글 수: 1

Most of the time, you would use tic and toc to obtain elapsed time.
You can also use
tin = clock;
do your code
tout = clock;
how_long = etime(tout, tin) %seconds
You can also
tin = datetime();
do your code
tout = datetime();
how_long = seconds(tout - tin) %seconds

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by