Here is what the matrix would look like:
There are 8 columns and say 100 rows, the random numbers in any row sum to 1.
.125 .125 .125 .125 ....... .125
.005 .105 .005 .205 ....... .205
.002 .003 .012. 201 ....... .200
...
Could Matlab automatically creates this kind of matrix, i.e. a right stochastic matrix? I am looking for a script.
Use bsxfun
rather than repmat
:
mat = rand(100, 8);
rowsum = sum(mat,2);
mat = bsxfun(@rdivide, mat, rowsum);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With