Filter löschen
Filter löschen

counting number of times a values appears in file

1 Ansicht (letzte 30 Tage)
aditi
aditi am 12 Sep. 2014
Beantwortet: Naama am 12 Sep. 2014
i have a file with numbers like...
1
2
3
4
2
1
6
4
and so on...
i want to count how many times each number appears in above file.. how to do that??

Antworten (2)

Andrei Bobrov
Andrei Bobrov am 12 Sep. 2014
a = [1, 2, 3, 4, 2, 1, 6, 4]';
a1 = unique(a);
out = [a1 histc(a,a1)];

Naama
Naama am 12 Sep. 2014
You can use hist (assuming that you import your data to the x vector):
[count, bin] = hist(x, min(x):max(x));
where count contains the frequency of the numbers in bin.

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by