find how many times same element is repeated
2 views (last 30 days)
Show older comments
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 Comment
madhan ravi
on 4 Apr 2019
Note you have a mistake in your desired result 6,7 has repeated once and 7,6 has repeated twice.
Accepted Answer
madhan ravi
on 4 Apr 2019
Edited: madhan ravi
on 4 Apr 2019
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 Comments
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!