comparing probability with random draw and choose a transition state
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Ive J
on 23 Jan 2021
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
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!