Using "rand" to randomize percent probability between two numbers

11 次查看(过去 30 天)
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.

采纳的回答

Image Analyst
Image Analyst 2016-4-10
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 个)

类别

Help CenterFile Exchange 中查找有关 Hypothesis Tests 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by