mercredi 8 novembre 2017

Obtaining the position of a random 1 in an array of 0's

I have a matrix which is initialized as follows:

stateAndAction = zeros(11, 4);

Over time the matrix will be updated so that at a given index, there will be a one. So at any given time we could have something that looks like this

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

How do I find a random row and column with a one in it?

This is the function signature I had in mind:

[random_row_index, random_column_index] = findRandom(stateAndAction)




Aucun commentaire:

Enregistrer un commentaire