while running a matlab program it shows error Subscript indices must either be real positive integers or logicals.
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
The program is given here
Let NP = population size =10;
D = Number of variables = 3;
pop = [2 4 6; 8 10 12; 5 10 15, 10 20 30; 33 22 11;3 6 9; 5 15 25; 12 24 30; 4 8 12; 8 16 20];
y is the population index that corresponds to best fitness
for np=1:NP
r1=round(unifrnd(1,NP));
while (r1==np)
r1=round(unifrnd(1,NP));
end
for j=1:D
newpop(np,j)=0;
newpop(np,j)=pop(np,j)+round(unifrnd(-1,1)*(pop(y,j)-pop(r1,j)));
end
end
댓글 수: 9
the cyclist
2015년 9월 5일
I could not run your code because I don't know what y is.
NP = 10;
D = 3;
pop = [2 4 6;
8 10 12;
5 10 15;
10 20 30;
33 22 11;
3 6 9;
5 15 25;
12 24 30;
4 8 12;
8 16 20];
for np=1:NP
r1=round(unifrnd(1,NP));
while (r1==np)
r1=round(unifrnd(1,NP));
end
for j=1:D
newpop(np,j)=0;
newpop(np,j)=pop(np,j)+round(unifrnd(-1,1)*(pop(y,j)-pop(r1,j)));
end
end
balaji
2015년 9월 5일
the cyclist
2015년 9월 5일
The following code ran to completion for me, without error.
NP = 10;
D = 3;
y = 10;
pop = [2 4 6;
8 10 12;
5 10 15;
10 20 30;
33 22 11;
3 6 9;
5 15 25;
12 24 30;
4 8 12;
8 16 20];
for np=1:NP
r1=round(unifrnd(1,NP));
while (r1==np)
r1=round(unifrnd(1,NP));
end
for j=1:D
newpop(np,j)=0;
newpop(np,j)=pop(np,j)+round(unifrnd(-1,1)*(pop(y,j)-pop(r1,j)));
end
end
Can you post a self-contained piece of code that actually gives the error? (Just make a comment here. Don't post a whole new question again.)
balaji
2015년 9월 5일
편집: Walter Roberson
2015년 9월 6일
the cyclist
2015년 9월 5일
That code does not run for me, because "np" is not defined. Also, "xmin" is not defined.
Again, can you please try to construct a piece of code that we can just paste into a mat files and run, that will show the error?
balaji
2015년 9월 5일
balaji
2015년 9월 5일
편집: Walter Roberson
2015년 9월 6일
Image Analyst
2015년 9월 5일
Read this then fix: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup Or else, just attach your m-file with the paper clip icon.
Walter Roberson
2015년 9월 6일
We cannot run this, as ED is not defined. If it is an array then you are attempting to index the array at location 0.
We need to full error message showing exactly which line is triggering the error message for you.
답변 (0개)
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!