フィルターのクリア

code that generate 50 by 50 matrix of 0's and 1's of which 20% is 1's.

4 ビュー (過去 30 日間)
Kelil Mohammed
Kelil Mohammed 2018 年 6 月 11 日
編集済み: Stephen23 2018 年 6 月 12 日
I want to create matrix of 0's and 1's of which 20% of the elements of the matrix is 1's. The following the code I tried. neighbor_matrix = [ones(10,50);zeros(40,50)]; But the out come is not in the way I want. I want the distribution shouldn't be 1's and 0's are in separate manner. Thank you.

採用された回答

Stephen23
Stephen23 2018 年 6 月 11 日
編集済み: Stephen23 2018 年 6 月 12 日
>> M = +(rand(50,50)<0.2);
>> mean(M(:)) % testing
ans = 0.19880

その他の回答 (1 件)

Matt J
Matt J 2018 年 6 月 11 日
neighbor_matrix = [ones(10,50);zeros(40,50)];
neighbor_matrix(:)=neighbor_matrix(randperm(2500));

カテゴリ

Help Center および File ExchangeAntennas, Microphones, and Sonar Transducers についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by