Counting the number of occurences for specific values in an array

조회 수: 1 (최근 30일)
Shady Elsayed
Shady Elsayed 2020년 5월 26일
답변: Rik 2020년 5월 26일
I have an array that reads [ 1 2 3 4 5 5 4 3 2 1 ] and I want to count the number of occurences of each element
so that it gives me an array of [ 2 2 2 2 2 ]
I tried using
x(i)=sum[array(i)==array] but it gives me [ 2 2 2 2 2 2 2 2 2 2 2 ]

답변 (1개)

Rik
Rik 2020년 5월 26일
a=[ 1 2 3 4 5 5 4 3 2 1 ] ;
histcounts(a)
If you have non-integer data you can use the unique function to convert your vector to positive integers.

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by