Normal random number generation

14 ビュー (過去 30 日間)
Sushant
Sushant 2022 年 9 月 22 日
編集済み: Torsten 2022 年 9 月 22 日
I want to generate some random numbers which should lie between 0 and 1. Also those values should follow nornal ditribution. Is there any readymade function for it, in MATLAB?
  1 件のコメント
Dyuman Joshi
Dyuman Joshi 2022 年 9 月 22 日
編集済み: Dyuman Joshi 2022 年 9 月 22 日
You can normalize the data in between 0 to 1, though I am not sure if it will still follow normal distribution or not.
y=randn(1,7)
y = 1×7
-2.3212 -0.6273 -0.4058 0.3280 0.0769 1.5305 -0.0685
y=(y-min(y))/(max(y)-min(y))
y = 1×7
0 0.4398 0.4973 0.6878 0.6226 1.0000 0.5849
I also recommend you check out these comments -

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

回答 (2 件)

Torsten
Torsten 2022 年 9 月 22 日
編集済み: Torsten 2022 年 9 月 22 日
pd = makedist('Normal');
t = truncate(pd,0,1);
r = random(t,1e6,1);
figure(1)
histogram(r,100)
Or directly:
r = -sqrt(2)*erfinv(rand(1e6,1)*erf(-1/sqrt(2)));
figure(2)
histogram(r,100)
Of course, the random numbers are not normally distributed in the usual sense.
  1 件のコメント
Dyuman Joshi
Dyuman Joshi 2022 年 9 月 22 日
Quite a neat function.
However, OP might not have access to Stats and ML toolboox.

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


Bruno Luong
Bruno Luong 2022 年 9 月 22 日
Here is an alternatve without stats tbx
X=TruncatedGaussian(-1,[0 1],[1, 1e6]);
histogram(X)

カテゴリ

Help Center および File ExchangeDescriptive Statistics and Visualization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by