フィルターのクリア

How can I figure out which element in the array is repeated and how many times?

2 ビュー (過去 30 日間)
Võ Kiet
Võ Kiet 2021 年 8 月 18 日
コメント済み: Võ Kiet 2021 年 8 月 22 日
Hi every one, I have a problem with matrix.
Code:
A = {''A'', "B", ''C''; "D", "E", "F"; ''A'', "G", "H"; ''C'', "Y", "C"};
How can I figure out which element in the array is repeated and how many times?
Thanks and Best Regards,
Kiet Vo

採用された回答

Wan Ji
Wan Ji 2021 年 8 月 18 日
Hi, friend, using histcounts, things will be simple
A = {'A', 'B', 'C'; 'D', 'E', 'F'; 'A', 'G', 'H'; 'C', 'Y', 'C'};
A = categorical (A);
[counts, val] = histcounts(A)
Results become
counts =
2 1 3 1 1 1 1 1 1
val =
1×9 cell 数组
{'A'} {'B'} {'C'} {'D'} {'E'} {'F'} {'G'} {'H'} {'Y'}
  8 件のコメント
Wan Ji
Wan Ji 2021 年 8 月 21 日
That's Simple to solve
function [x, characters, counts]= another_function(A)
A = categorical (A);
[counts, val] = histcounts(A);
q = counts>=2;
counts = counts(q);
characters = val(q);
x = 2*counts;
end
Võ Kiet
Võ Kiet 2021 年 8 月 22 日
Yaaaa, I got it. Thanks so much for your support =v=

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by