randomly pick number from a matrix in matlab
17,663
Solution 1
If your matrix is M
then to pick a random element with uniform probability you can use randi
:
M(randi(numel(M)))
Solution 2
Yes, using randi:
A(randi(numel(A)))
Author by
happyme
Updated on June 04, 2022Comments
-
happyme almost 2 years
How can i randomly pick a number from the given following matrix below?
A=[0.06 0.47 0.47]
I just want to randomly pick a number from the matrix above. I am doing this in matlab enviornment. please help. Also, Is it possible assume a variable in matlab that tends to zero, like we do in limits?
-
bla about 11 years
length
can be not suitable if the array's dimensions are bigger than 1. -
shoelzer about 11 yearsTrue, but the example is 1 x 3 so this does what is asked. I guess that answering the question in general is probably better than just working with the example, though.