필터 지우기
필터 지우기

find the number of occurances

조회 수: 3 (최근 30일)
johnson saldanha
johnson saldanha 2018년 11월 13일
댓글: johnson saldanha 2018년 11월 13일
my matrix is x=[ 1 1 1 3 3 4 4 4 6 7]
i want the output as y=[ 3 2 3 1 1]
i want to find how many times a particular value is occuring

채택된 답변

Stephan
Stephan 2018년 11월 13일
편집: Stephan 2018년 11월 13일
y=sum(x(:)==unique(x))
Since 3 is occuring 2 times, the correct result is:
y=[3 2 3 1 1]
Best regards
Stephan
  댓글 수: 6
Stephan
Stephan 2018년 11월 13일
if you dont get it to work with this, use madhans code below.
johnson saldanha
johnson saldanha 2018년 11월 13일
yeah i tried that it works. thank you

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

추가 답변 (1개)

madhan ravi
madhan ravi 2018년 11월 13일
x=[ 1 1 1 3 3 4 4 4 6 7]
u = unique(x) %unique numbers
y=histc(x,u) %occurences
bonus = [u; y]' %relation between them
  댓글 수: 2
johnson saldanha
johnson saldanha 2018년 11월 13일
thanks.
madhan ravi
madhan ravi 2018년 11월 13일
Anytime :)

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by