Why unifrnd(lb,ub,[nPop,D]) gives error?

조회 수: 18(최근 30일)
Sadiq Akbar
Sadiq Akbar 2020년 12월 26일
댓글: Rik 2021년 1월 3일
이 질문에 1명의 참여자가 플래그를 지정함
Why the following code gives error?
lb=[0 0 0 0]; ub=[10 10 pi pi]; nPop=30; D=4;
unifrnd(lb,ub,[nPop,D])
Error using unifrnd
Size information is inconsistent.
  댓글 수: 1
Rik
Rik 2021년 1월 3일
Deleted comments can be found in the Google cache (the archived version will require modification of the attributes, as the show/hide comments toggle doesn't execute properly).

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

답변(1개)

Ameer Hamza
Ameer Hamza 2020년 12월 26일
This cannot be done in single call to unifrnd. You need a for-loop
lb = [0 0 0 0]; ub=[10 10 pi pi]; nPop=30;
D = numel(lb);
M = rand(nPop, D);
for i = 1:D
M(:,i) = unifrnd(lb(i),ub(i),[nPop,1]);
end
  댓글 수: 31
Sadiq Akbar
Sadiq Akbar 2020년 12월 28일
Further, when i rant it with my own old fitness function (before your chnages), again it gave error as:
Subscripted assignment dimension mismatch.
Error in fun2sn0 (line 13)
[~, ix1(ix)] = sort(b); % temp stores the randomly generated vector "best" by algorithm
Error in GQPSO (line 54)
f_x(i) = feval(fun,x(i, :));
Error in myfit_driver (line 2)
[xmin,fmin,histout] = GQPSO(@fun2sn0,4,30,[0 0 0 0],[10 10 pi pi],2000,10000*4);

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

Community Treasure Hunt

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

Start Hunting!

Translated by