How to make a random vector in Matlab as a ones and zeros but under control?

4 ビュー (過去 30 日間)
How to make a random vector in Matlab as a ones and zeros with this condition, that the number of ones be under my control. which it means i want the random vector with fix number of ones but totally random in positions. for example: this line will make a random number 0 and 1 also it's totally random in the vector but i cannot control number of 1 and 0 e.g i need number of 1 be 90 and the rest 0 or any other number V1=round(rand(1,256));

採用された回答

Thorsten
Thorsten 2015 年 11 月 11 日
r = zeros(1,256);
r(randperm(256, 90)) = 1;
  1 件のコメント
Hamid Reza Barzegar
Hamid Reza Barzegar 2015 年 11 月 11 日
Thank you. it seems working. i should try it in the main program.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by