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

10 ビュー (過去 30 日間)
Sadiq Akbar
Sadiq Akbar 2020 年 12 月 26 日
コメント済み: Rik 2021 年 1 月 3 日
この 質問 は Walter Roberson さんによってフラグが設定されました
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);

サインインしてコメントする。

カテゴリ

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by