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

 Respuesta aceptada

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

Más respuestas (1)

Categorías

Más información sobre Entering Commands en Centro de ayuda y File Exchange.

Preguntada:

el 26 de Dic. de 2013

Respondida:

el 26 de Dic. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by