Using "rand" to randomize percent probability between two numbers
11 views (last 30 days)
Show older comments
How would you write a code to do these probabilities? These probabilities are all related, so for example it would mean one helicopter has all of these probabilities to rise or fall a certain meter.
50% probability between 0m to 25m
10% probability between 25m to 50m.
5% probability between 50m to 75m.
20% probability between 0m to 50m.
10% probability between 50m to 150m.
5% probability between 150m to 200m.
There is an equal probability of any value between the two values.
0 Comments
Accepted Answer
Image Analyst
on 10 Apr 2016
Do you mean like this:
r = rand;
if r < .5
% 50% probability between 0m to 25m
elseif r < 0.6
% 10% probability between 25m to 50m.
elseif r < 0.65
% 5% probability between 50m to 75m.
elseif r < 0.85
% 20% probability between 0m to 50m.
elseif r < 0.95
% 10% probability between 50m to 150m.
else
% 5% probability between 150m to 200m.
end
You get a random number and then test it. You will go into the respective blocks of the "if" with the designated probabilities. Then inside the block you can do whatever you want, such as set the altitude or change in altitude or whatever.
0 Comments
More Answers (0)
See Also
Categories
Find more on Hypothesis Tests 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!