How can one create a random matrix (say B) which element B(i,j) is a uniform random integer number in the close interval 0 and A(i,j). A is a given matrix. For example:
A = [6, 2, 5, 7;
12, 0, 4, 0;
8, 0, 10, 1;
11, 6, 2, 5];
B = floor(rand(size(A)).*(A+1))
Explanation
rand(size(A)) creates a matrix of the same size as A, with elements uniformly distributed between 0 and 1.rand(size(A)).*(A+1) each element (i, j) is a random distribution between 0 and A(i, j)+1floor(rand(size(A)).*(A+1)) each unit width range is mapped to the nearest lower integerNote that B = round(rand(size(A)).*A) will almost do the same, except that 0 and A(i, j) will have less probability to occur.