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

2 Ansichten (letzte 30 Tage)
BigWaffle
BigWaffle am 23 Mär. 2021
Beantwortet: Image Analyst am 23 Mär. 2021
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

Akzeptierte Antwort

Star Strider
Star Strider am 23 Mär. 2021
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
.

Weitere Antworten (2)

William
William am 23 Mär. 2021
... or maybe histcounts(R12) to get a histogram.

Image Analyst
Image Analyst am 23 Mär. 2021
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)

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by