counting number of times a values appears in file

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??

回答 (2 件)

Andrei Bobrov
Andrei Bobrov 2014 年 9 月 12 日

0 投票

a = [1, 2, 3, 4, 2, 1, 6, 4]';
a1 = unique(a);
out = [a1 histc(a,a1)];
Naama
Naama 2014 年 9 月 12 日

0 投票

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.

カテゴリ

ヘルプ センター および File ExchangeDevelop Apps Using App Designer についてさらに検索

質問済み:

2014 年 9 月 12 日

回答済み:

2014 年 9 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by