How can i randomly insert 14 1's in a array of two thousand zeros?

2 ビュー (過去 30 日間)
Taikhum Vahanvaty
Taikhum Vahanvaty 2020 年 8 月 7 日
コメント済み: Taikhum Vahanvaty 2020 年 8 月 7 日
i.e. I have a array of two thousand zeros, in this I want to randomly insert 1, fourteen times. How can I do this?

採用された回答

John D'Errico
John D'Errico 2020 年 8 月 7 日
A = zeros(1,2000);
A(randperm(2000,14)) = 1;
  1 件のコメント
Taikhum Vahanvaty
Taikhum Vahanvaty 2020 年 8 月 7 日
Thank you John! This solves my problem :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by