Randomly Error - index must be a positive integer or logical

1 回表示 (過去 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 Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by