Re: to input zeros randomly into matrix
- From: "Jason" <gaudetteje@xxxxxxxxx>
- Date: 30 Apr 2006 07:46:04 -0700
I suspect there is a simpler way to do what you're trying to accomplish
using the binomial distribution, but to answer the question you stated
you should use the 'find' command.
M = round(rand(10,30)); % assumes P = 1/2
cols = find(sum(M,1)>2 & sum(M,1)<=5);
M = M(:,cols(1:10)) % take first 10 columns satisfying criteria
sum(M,1) % check
Note that rather than replacing random 0 or 1 values in each column
that doesn't meet your criteria, it is much easier to just replace that
row with one that does.
For extra credit, choosing the number of columns in M that will meet
your criteria can be determined rather simply by applying the binomial
distribution. Otherwise, you can just overcompensate since you're
dealing with such a small amount of data.
Let me know what grade I get from your prof!
-Jay
.
- References:
- to input zeros randomly into matrix
- From: Wilson
- to input zeros randomly into matrix
- Prev by Date: Re: 3-D plots help
- Next by Date: Re: circular shifting a vector/matrix - Problem
- Previous by thread: to input zeros randomly into matrix
- Next by thread: Re: to input zeros randomly into matrix
- Index(es):