comparing probability with random draw and choose a transition state

2 ビュー (過去 30 日間)
Sehrish Usman
Sehrish Usman 2021 年 1 月 23 日
回答済み: Ive J 2021 年 1 月 23 日
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 Center および File ExchangeFunctions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by