Re: a random matrix of zeros and ones with exactly N ones
- From: Omid <omid@xxxxxxxxxxxxx>
- Date: Fri, 15 Sep 2006 10:39:00 -0400
Steve Amphlett wrote:
9
Omid wrote:
elements
How can I generate a random matrix of a defined size with
zero or one with exactly M ones? For example a 4*5 matrix with
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.
You need <randperm>
x=ones(9,1);
x(20)=0;
x=reshape(x(randperm(20)),4,5)
And you can probably do it on one line if you want to be clever.
I don't want to be cleverer than you ;) Thanks for your help.
.
- References:
- a random matrix of zeros and ones with exactly N ones
- From: Omid
- Re: a random matrix of zeros and ones with exactly N ones
- From: Steve Amphlett
- a random matrix of zeros and ones with exactly N ones
- Prev by Date: Re: a random matrix of zeros and ones with exactly N ones
- Next by Date: Re: Repeat Texture as Background Image
- Previous by thread: Re: a random matrix of zeros and ones with exactly N ones
- Next by thread: Re: a random matrix of zeros and ones with exactly N ones
- Index(es):
Relevant Pages
|