필터 지우기
필터 지우기

How can i create a sequence where the symbols have different probabilities?

조회 수: 2 (최근 30일)
Gn Gnk
Gn Gnk 2020년 7월 9일
편집: Apoorv Singh 2020년 7월 9일
Hello ,
I have 4 symbols 0,1,2,3 . How can i create a sequence with these symbols where every symbol should have each own probabilty .For example i want the symbols 1,2 to appear with probability q , but in the other hand the symbols 1,4 to appear with probability (1-q)/2.
In my last excersice i was asked to create a sequence where these symbols have the same probability 1/4 so i wrote the code below:
C = floor(rand(1,n)*4);
But i am little confused about this issue .Any help would be valuable.
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 7월 9일
hint:
probabilities 0.1, 0.23, 0.6, 0.07
random number < 0.1 is the first symbol
random number between 0.1 and 0.1+0.23 is the second symbol
random number between 0.1+0.23 and 0.1+0.23+0.6 is the third symbol...

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

답변 (1개)

Apoorv Singh
Apoorv Singh 2020년 7월 9일
편집: Apoorv Singh 2020년 7월 9일

Walter has suggested a nice method. You basically partition the range [0:1] into partitions proportional to the probabilities. As calling rand outputs a decimal in the range [0:1] with equal probability, your problem will be solved.

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by