How to select a random number from a set of numbers

Got a little dilemma. Can you guys help me select a random number from a set of numbers. Using this code,
p = [0.4399,0.4138,0.3888,0.3650,0.3377,0.3120]; pos = randi(length(p)); AirDensity = p(pos)
I can get Matlab to choose one of those numbers from my set of values but it keeps selecting the same numbers over and over again. I think this is because "pos" has been attributed a number in the line before. Is there anyway to get Matlab to choose a different one every time so that only the last line of code needs repeating ?
Many thanks :)
G

 Accepted Answer

doc randperm %?
E.g.
x = sin(1:10);
x(randperm(numel(x),3))

More Answers (1)

Categories

Asked:

on 26 Dec 2013

Answered:

on 26 Dec 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!