find how many times same element is repeated

1 回表示 (過去 30 日間)
NA
NA 2019 年 4 月 4 日
コメント済み: madhan ravi 2019 年 4 月 4 日
A=[9,8;7,6;1,2;2,4;3,4;3,4;4,7;6,7;8,6;9,8;7,6];
a = sort(unique(A,'rows'),2);
a is [1,2;2,4;3,4;4,7;6,7;6,7;6,8;8,9];
I want to get how many times same element is repeated,
[1,2] repeated 1,[2,4] repeated 1, [3,4] repeated 2, [1,2] repeated 1, [4,7] repeated 1, [6,7] repeated 2
  1 件のコメント
madhan ravi
madhan ravi 2019 年 4 月 4 日
Note you have a mistake in your desired result 6,7 has repeated once and 7,6 has repeated twice.

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

採用された回答

madhan ravi
madhan ravi 2019 年 4 月 4 日
編集済み: madhan ravi 2019 年 4 月 4 日
A=[9,8;7,6;1,2;2,4;3,4;3,4;4,7;6,7;8,6;9,8;7,6];
a = unique(A,'rows');
R = zeros(size(a,1),1);
for k = 1:size(a,1)
R(k) = nnz(ismember(A,a(k,:),'rows'));
end
Result = table(a,R,'VariableNames',{'Rows','Times'})
Gives:
Result =
8×2 table
Rows Times
______ _____
1 2 1
2 4 1
3 4 2
4 7 1
6 7 1
7 6 2
8 6 1
9 8 2
>>

その他の回答 (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