Re: a random matrix of zeros and ones with exactly N ones



Omid wrote:


How can I generate a random matrix of a defined size with elements
zero or one with exactly M ones? For example a 4*5 matrix with 9
ones
and 11 zeros. I want it to be completely random such that the
generated matrix be able to span the space of all possible
permutations of zeros and ones (M ones)in the matrix.

See NTRUE:
<http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=10924&objectType=FILE>

A = ntrue(9,4,5) ;
It uses randperm to fill the entries, as in the other replies.

hth
Jos
.



Relevant Pages

  • Re: a random matrix of zeros and ones with exactly N ones
    ... Omid wrote: ... How can I generate a random matrix of a defined size with ... permutations of zeros and ones in the matrix. ... And you can probably do it on one line if you want to be clever. ...
    (comp.soft-sys.matlab)
  • Re: Sorting the column in a matrix
    ... After I produce a random matrix with zeros and ones, ... then put the same column in one empty array, ...
    (comp.soft-sys.matlab)
  • Re: a random matrix of zeros and ones with exactly N ones
    ... Omid wrote: ... How can I generate a random matrix of a defined size with elements ... permutations of zeros and ones in the matrix. ... And you can probably do it on one line if you want to be clever. ...
    (comp.soft-sys.matlab)
  • Sorting the column in a matrix
    ... After I produce a random matrix with zeros and ones, ... then put the same column in one empty array, ...
    (comp.soft-sys.matlab)
  • a random matrix of zeros and ones with exactly N ones
    ... How can I generate a random matrix of a defined size with elements ... generated matrix be able to span the space of all possible ... permutations of zeros and ones in the matrix. ...
    (comp.soft-sys.matlab)