Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

randomly pick number from a matrix in matlab

Tags:

matrix

matlab

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?

like image 496
happyme Avatar asked Jan 28 '13 20:01

happyme


People also ask

How do you randomly select a number in a matrix in MATLAB?

You can use the randperm function to create a double array of random integer values that have no repeated values. For example, r4 = randperm(15,5);

How do I randomly select data in MATLAB?

To sample random integers without replacement, use randperm or datasample . To randomly sample from data, with or without replacement, use datasample .


2 Answers

If your matrix is M then to pick a random element with uniform probability you can use randi:

 M(randi(numel(M)))
like image 99
bla Avatar answered Nov 16 '22 04:11

bla


Yes, using randi:

A(randi(numel(A)))
like image 30
shoelzer Avatar answered Nov 16 '22 03:11

shoelzer