Randomly Error - index must be a positive integer or logical
Show older comments
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
Answers (5)
Bugar Waristara
on 23 Jun 2011
1 vote
2 Comments
Walter Roberson
on 23 Jun 2011
if any(YourArray(:)==0)
then there is a 0.
More robust would be to check
if any(YourMatrix(:) < 1 | YourMatrix(:) ~= fix(YourMatrix(:))
Krishna Kumar
on 24 Jun 2011
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
on 23 Jun 2011
0 votes
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
on 23 Jun 2011
0 votes
Krishna Kumar
on 23 Jun 2011
0 votes
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
on 29 Jun 2012
0 votes
Send me your code, its been removed by media fire, so I can help you as soon as possible. Mjid.yazdani@gmail.com
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!