フィルターのクリア

How to produce 1 and -1 in MATLAB

1 回表示 (過去 30 日間)
charu shree
charu shree 2023 年 7 月 1 日
コメント済み: charu shree 2023 年 7 月 1 日
Hello all, I want to generate 2000 numbers out of which 50% times it should be +1 and for remaining 1000 it should be -1.
Any help in this regard will be highly appreciated.

回答 (1 件)

Jan
Jan 2023 年 7 月 1 日
編集済み: Jan 2023 年 7 月 1 日
Exactly 50% or randomly?
x = randi([0, 1], 1, 2000) * 2 - 1;
y = [ones(1, 1000), -ones(1, 1000)];
y = y(randperm(y));
  1 件のコメント
charu shree
charu shree 2023 年 7 月 1 日
Thanks a lot sir for your response.... Exactly 50%

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by