フィルターのクリア

Matrix dimension must agree

2 ビュー (過去 30 日間)
Cesar Ramirez
Cesar Ramirez 2019 年 2 月 25 日
編集済み: Kevin Phung 2019 年 2 月 25 日
Hi , I get error when trying to make xh = xp + r.
xl = [-5,-5] ;
xu = [5,5] ;
D = 2 ;
g =1000;
xp = xl+(xu-xl).*rand(0,1) ;
sigma = 1;
for i=1:g
r = normrnd(0,sigma^2,[D 1]);
xh = xp + r;

回答 (1 件)

Kevin Phung
Kevin Phung 2019 年 2 月 25 日
編集済み: Kevin Phung 2019 年 2 月 25 日
you are not using rand correctly. from the documentation:
"X = rand returns a single uniformly distributed random number in the interval (0,1).
X = rand(n) returns an n-by-n matrix of random numbers.
X = rand(sz1,...,szN) returns an sz1-by-...-by-szN array of random numbers where sz1,...,szN indicate the size of each dimension. For example, rand(3,4) returns a 3-by-4 matrix."
my guess is you were just trying to do:
xp = xl+(xu-xl).*rand; %without the (0,1) argument

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by