MATLAB: Create a random matrix

random matrix

I want to create a random matrix HM (a,b), it satisfies the following conditions:
1. The value of HM is a nonnegative integer from 0 to c.
2. The total value of the elements in a row is less than or equal to d.
you are way that uses loop to made that.
Thanks!

Best Answer

HM = zeros(a,b);
for k = 1:a
t = zeros(c,b);
t(randperm(b*c,d)) = 1;
HM(k,:) = sum(t,1);
end
Note: This is not a rejection method.