Using "rand" to randomize percent probability between two numbers

9 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Image Analyst
Image Analyst am 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.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by