mercredi 15 juillet 2015

How to generate a matrix with randomly distributed clusters of numbers in MatLab?

I can generate a matrix of randomly placed 1's and 0's by using round(rand(100,100)) for instance. How can I generate a similar matrix where instead of 1's there are a given number of randomly distributed square sub-matrices of 1's of a given size? For example:

0 0 0 0 0 0 0 0
0 1 1 0 0 0 0 0
0 1 1 0 0 0 1 1
0 0 0 0 0 0 1 1
1 1 0 0 1 1 0 0
1 1 0 0 1 1 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0

The matrix above has 4 randomly placed sub-matrices of 1's of size 2.




Aucun commentaire:

Enregistrer un commentaire