comparing probability with random draw and choose a transition state

1 次查看(过去 30 天)
I want to compare probability of an event with a randomly drawn number and then choose an event based on different conditions across various time periods.
for example, my probability matrix for three time periods is;
P =[0.8 0.9 0.2; 0.3 0.6 0.5]
and randomly drawns numbers matrix is
R = [0.6 0.3 0.5; 0.4 0.5 0.7]
then I need to compare each column of R with each column of P, and applya condition like if R is greater than P, event1 will happen otherwise event2 will happen.
The outcome should be
Events = [event2 event2 event1 ; event1 event2 event1]
Finally I need to count for each row how many transitions occur. For example for row 1, event2 occurs twice and event1 occurs once.
Can anyone help me how to start the code for it? or any relevant tip. Many thanks

回答(1 个)

Ive J
Ive J 2021-1-23
You can construct events by a simple element-wise comparison:
events = R < P;
event2_num = sum(events, 2);
event1_num = sum(~events, 2);
events = events + 1; % event2 becomes 2, and event1 becomes 1

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by