comparing probability with random draw and choose a transition state

조회 수: 1 (최근 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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by