how to make a matrix elements randomly distributed

1 次查看(过去 30 天)
how to make a matrix m elements, which has n elements "one" or #0, randomly distributed, the remaining elements are zero (n<m).

采纳的回答

David Sanchez
David Sanchez 2013-6-21
Try this out (adapt the values to your needs):
m = 10;
n = 3;
pos = randperm(m*n,m);
M = zeros(m,n);
M(pos) = 1;
M =
0 0 0
1 1 0
0 1 1
0 0 0
1 0 0
0 0 0
0 0 0
1 0 1
0 1 1
0 0 1
M has the ones randomly distributed.

更多回答(1 个)

Pham Ngoc Thanh
Pham Ngoc Thanh 2013-6-21
thanks a lot.

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by