Re: to input zeros randomly into matrix
- From: Jos <x@xxx>
- Date: Sun, 30 Apr 2006 13:53:25 -0400
Wilson wrote:
Hi Guys,
If i have a random matrix such as
matrix =
1 0 1 0 0 1 0 1 0 1
0 1 1 1 0 1 0 1 0 0
0 1 0 0 1 0 0 1 1 1
1 0 0 1 0 0 1 1 0 1
0 1 0 1 1 0 1 1 1 0
1 1 0 1 1 0 1 1 1 1
0 0 1 0 1 0 1 1 0 0
1 0 1 0 1 0 0 0 1 0
1 0 1 0 0 0 0 0 0 1
1 1 0 1 0 1 0 1 0 0
and
sum(matrix)
ans =
6 5 5 5 5 3 4 8 4 5
is there anyway for me to be able to check if say for every column
there should be more than 2 ones and no more than 5 ones? if there
is
more than 5 ones for eg, i have to randomly change 1 = 0 for any
(i,j) component
Cheers!~
To create a M-by-N matrix a with a random number of ones between 2
and 5 in each of the e.g. N columns, you can use:
M = 10 ;
N = 6 ;
n = 1+ceil(4*rand(1,6)) ; % random
X = nones(n) ;
if M > size(X,1), X(M,N) = 0 ; end
X = shake(X) ;
isequal(sum(X),n) % test
Both <shake> and <nones> can be found on the matlab file
exchange.
hth (getting your grade)
Jos
.
- References:
- to input zeros randomly into matrix
- From: Wilson
- to input zeros randomly into matrix
- Prev by Date: .mat file conversion for Excel
- Next by Date: Mean for non-zero elements
- Previous by thread: Re: to input zeros randomly into matrix
- Next by thread: simevents/stateflow data exchange
- Index(es):
Relevant Pages
|