find how many times same element is repeated

3 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by