Given a set of elements (expressed in a row vector Vi
) I extracted the maximum values into another (row) vector (named 'ki') using [ki] = find(Vi==max(max(Vi)))
. I say values because a lot of numbers repeat. I have to choose randomly between all the repeated values and know the column of the chosen one. For that i made the following code.
ri=rand(1)
for j=1:length(ki)
if ((j-1)/length(ki)<ri<=j/length(ki))
mi=ki(j)
endif;
endfor
if (ri==0)
mi=ki(1)
endif
The problem is that it always gives me mi=ki(last 'j' of the for cycle)
(which in this case is mi=ki(length(ki))
).
I suspect there must be some elemental logical failure. Forgive my n00bness.
Bye
Aucun commentaire:
Enregistrer un commentaire