请教, 如何产生一个取值为1​的概率为二分之一,取​值为-1的概率为二分​之一的40*50的`​随机矩阵。

如题随机矩阵的行列分别为40*50. 元素只有1和-1, 其中取1的概率为二分之一,取-1的概率为二分之一.

 採用された回答

novong
novong 2023 年 5 月 14 日

0 投票

m = ones(40,50);
m(rand(size(m))>0.5) = -1;

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange随机数生成 についてさらに検索

タグ

質問済み:

2023 年 5 月 14 日

回答済み:

2023 年 5 月 14 日

Community Treasure Hunt

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

Start Hunting!