Randomly Error - index must be a positive integer or logical

조회 수: 2 (최근 30일)
Bugar Waristara
Bugar Waristara 2011년 6월 23일
Hello All,
Now, I develop a program based on m-file. My program was based on Genetic Algorithm to solve Vehicle Routing Problem with Time Window (VRPTW) case.
But when I run it, it come to this -index must be a positive integer or logical- kind of error.
Because my program consist of more than one m-file, I afraid it will make you confuse if I just copy a part of that. So, I upload all in http://www.mediafire.com/?0u4a32bx0mz6gys
Please help me to solve this, it started to make me frustated. Thank you

답변 (5개)

Bugar Waristara
Bugar Waristara 2011년 6월 23일
I was not sure that there are any zeros value in my population because the member of the population generated from random number from 1-JumGen(integer positive number).
Is there are any method to check whether there are any zero in my population?
Thank you
  댓글 수: 2
Walter Roberson
Walter Roberson 2011년 6월 23일
if any(YourArray(:)==0)
then there is a 0.
More robust would be to check
if any(YourMatrix(:) < 1 | YourMatrix(:) ~= fix(YourMatrix(:))
Krishna Kumar
Krishna Kumar 2011년 6월 24일
Bugar,
Your population may be ok while initialization. But during course
of mutation, recombination etc( hope you use simple GA), the values in population may go beyond limits or become zero, negative etc. So Check that . If that is true, make sure the rogue values are re initialized in the limit.
HTh

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


Krishna Kumar
Krishna Kumar 2011년 6월 23일
Bugar, its difficult for us to solve it straightaway, since you didnt mention in which code the error occurs. The error is a common one. when use call sth like this c=A(:,r), where A is a matrix, r needs to be positive integer. if r is -ve or 0 or decimal, the error would be shown. Obviously MATLAB will tell you which code has the error. Put breakpoint at the point of error and see what the index is- negative, zero etc. This would suffice

Bugar Waristara
Bugar Waristara 2011년 6월 23일
Krishna, but when I run it, the m-file where the error occurs is random. Sometimes, it came from my mainHMOEA.m file, but in another time, it came from my HMOEAmutasi.m, the file which the output is used in mainHMOEA.m.
Basically, i always check the line that noted by the program as the error source and I sure that normally it will not get error. Can you please kindly check my file.
Thanks

Krishna Kumar
Krishna Kumar 2011년 6월 23일
Bugar From a brief review of code, I suppose that Tempopulasi is your population which is passed as input argument to other functions. This population matrix has zeros in it . So it causes problem in RuteA which in used as index somewhere. So make sure your population does not have zeros or negatives. Thats the way out for you. hth

majid yazdani
majid yazdani 2012년 6월 29일
Send me your code, its been removed by media fire, so I can help you as soon as possible. Mjid.yazdani@gmail.com

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by