How can I find the probability of each term in the array?

조회 수: 1 (최근 30일)
Onur Metin Mertaslan
Onur Metin Mertaslan 2020년 5월 5일
댓글: KSSV 2020년 5월 5일
Let's say we have an arrary such [1,1,2,3,5,5], how can I find the probability of the terms? I am quite new in Matlab and I could not solve the problem.
Thanks!
  댓글 수: 2
KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 5월 5일
편집: KALYAN ACHARJYA 2020년 5월 5일
One Way:
  • Get the array
  • Read the first element
  • Count the repetitions of the first element
  • pdf_first=repetitions/length(array)

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

답변 (1개)

KSSV
KSSV 2020년 5월 5일
A = [1,1,2,3,5,5] ;
P = nnz(A==1)/length(A) % probability of 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