How to select a random number from a set of numbers
Show older comments
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
More Answers (1)
Gabriel
on 26 Dec 2013
0 votes
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!