How to select a random number from a set of numbers
17 views (last 30 days)
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
0 Comments
Accepted Answer
More Answers (1)
See Also
Categories
Find more on Creating and Concatenating Matrices 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!