Create a multi value variable

Hi all:
I am trying to create a random variable that can take 5 values from 0 to 4 with the following probability distribution p0 = 0.36 P1 = 0.16 P2 = 0.16 P3 = 0.16 P4 = 0.16
Could you please help me in this.

댓글 수: 2

Roberto
Roberto 2014년 5월 19일
Please show some effort!!
Show us what you've tried... have a look at the RAND Function and try some of your ideas!
If you get stuck, we'll help!
Mahmoud
Mahmoud 2014년 5월 19일
Thank you Roberto. My problem is that I am not very experinced in MatLab so I didn't know where to start I will try RAND function. Thanks anyway

댓글을 달려면 로그인하십시오.

답변 (1개)

Roger Stafford
Roger Stafford 2014년 5월 19일

1 개 추천

To get you started here's a hint in the form of another question. In the following code what are all the possible values of the variable 's' and what are their respective probabilities?
c = [0.21,0.32,0.65,0.87];
r = rand;
s = sum(r<c);

댓글 수: 2

Mahmoud
Mahmoud 2014년 5월 19일
Thanks! If I understood it well then the possible values of s are
2.1, 4.96, 20.8, 37.41.
Roger Stafford
Roger Stafford 2014년 5월 20일
편집: Roger Stafford 2014년 5월 20일
No, you should try running that code repeatedly and see. Maybe it will give you some ideas.

댓글을 달려면 로그인하십시오.

제품

질문:

2014년 5월 19일

편집:

2014년 5월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by