How to find count of an item in a column of data in matlab?

1 回表示 (過去 30 日間)
Kunal Roy
Kunal Roy 2016 年 9 月 15 日
回答済み: Walter Roberson 2016 年 9 月 15 日
I need to find probabilities of each class for the implementation of a decision tree, in other words, the calculation of entropy and information gain. So, is there a function to get the count of each of several distinct items from a column?

回答 (2 件)

the cyclist
the cyclist 2016 年 9 月 15 日
I don't fully understand your question, but I think you should be able to use the unique command to get the counts of the distinct elements of a vector.

Walter Roberson
Walter Roberson 2016 年 9 月 15 日
Once you have the grouping number, you can use histc() or histcounts() over the number of different groups in order to get the counts.
If you have plain numeric variables instead of categorical arrays or something similar, then:
[uvals, ~, uidx] = unique(YourArray(:,colidx));
bincounts = histc(uidx, 1:length(uvals));
The unique value uvals(K) occurs bincounts(K) times.
If your values already happen to be positive integers starting from 1, then:
bincounts = accumarray( YourArray(:, colidx), 1);
after which the positive integer value K occurs bincounts(K) times

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by