フィルターのクリア

Help with cell count

2 ビュー (過去 30 日間)
FRANCISCO
FRANCISCO 2013 年 12 月 12 日
回答済み: Andrei Bobrov 2013 年 12 月 12 日
I now have a cell of 95 rows. Each row is a series of numbers that I want to sort and count the number of times they are repeated.
For example:
r2 = {[1, 4, 3, 1, 1, 6]};
I using
if true
% code
[r8,r9,r10]=cellfun(@unique,r2,'un',0);
end
I get "r8" that puts me the result properly:
   r8 = {[1, 3, 4, 6]}
But I want to find the number of times each number is repeated:
NUMBER_____________________________OCCURS
1 ----------------------------------3
2 ----------------------------------0
3 ----------------------------------1
4 ----------------------------------1
5 ----------------------------------0
6 ----------------------------------1
How could I do this?
Many thanks
  2 件のコメント
Walter Roberson
Walter Roberson 2013 年 12 月 12 日
Should the count be per-cell or over everything? Should the count be with respect to what was there before finding the unique values, or after the unique values (but over all the cells) ?
FRANCISCO
FRANCISCO 2013 年 12 月 12 日
The count is for each cell, that is:
r2={ [1;4;3;1] ; [2;2;3] };
The result is:
r3={ [1 2;2 0;3 1;4 1];[1 0;2 2;3 1] };

サインインしてコメントする。

採用された回答

Andrei Bobrov
Andrei Bobrov 2013 年 12 月 12 日
r2 = {[1, 4, 3, 1]; [2, 2, 3]};
r3 = cellfun(@(x)[(1:max(x))',accumarray(x(:),1)],r2,'un',0);

その他の回答 (1 件)

Image Analyst
Image Analyst 2013 年 12 月 12 日
I would call unique() on the cell contents first.
out = unique(in);
If the output is the same length as the input vector, then you know that no numbers are repeated and the counts are all 1. If it's shorter, there are some repeats, so in that case I'd use unique the unique numbers as the "edges" and call histc(array, edges) to get the counts of each unique number. Not hard - give it a shot!

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by