what function to use to find frequency of values in set?

조회 수: 2 (최근 30일)
BigWaffle
BigWaffle 2021년 3월 23일
답변: Image Analyst 2021년 3월 23일
How do I find number of occurence of a certain number in a set.
I have
R12= [5 6 1 2 6 1 2 1 2 6 5 2]
I need to find frequency of occurs of each number

채택된 답변

Star Strider
Star Strider 2021년 3월 23일
Try this:
R12= [5 6 1 2 6 1 2 1 2 6 5 2];
[R12u,~,ix] = unique(R12(:),'stable');
Number = R12u;
Count = accumarray(ix,1);
Result = table(Number, Count)
producing:
Result =
4×2 table
Number Count
______ _____
5 2
6 3
1 3
2 4
.

추가 답변 (2개)

William
William 2021년 3월 23일
... or maybe histcounts(R12) to get a histogram.

Image Analyst
Image Analyst 2021년 3월 23일
You could use histcounts:
R12= [5 6 1 2 6 1 2 1 2 6 5 2];
edges = [unique(R12), inf]
counts = histcounts(R12, edges)

카테고리

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

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by