Create a two-point distribution?

I want to multiply each element of a vector by a random variable X that takes values +1 and -1 with probability 1/2. How do I create this random variable?

回答 (1 件)

dk
dk 2019 年 10 月 17 日

1 投票

N=100;
x=sign(rand(N,1)-0.5);

1 件のコメント

kevin cecere palazzo
kevin cecere palazzo 2019 年 10 月 17 日
probability of getting sign(0)?

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

質問済み:

2019 年 10 月 17 日

コメント済み:

2019 年 10 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by