Re: to input zeros randomly into matrix



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

.