How can I figure out which element in the array is repeated and how many times?
    3 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
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
0 commentaires
Réponse acceptée
  Wan Ji
      
 le 18 Août 2021
        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 commentaires
  Wan Ji
      
 le 21 Août 2021
				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
Plus de réponses (0)
Voir également
Catégories
				En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

