If same value apperas in array count +1
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
First Last
le 14 Sep 2021
Commenté : First Last
le 14 Sep 2021
Hello Guys,
I have an array with nx1, now i need a code to count + 1 if the same value apperas later in the array, for example:
input = [ 1 2 3 4 1 2 3 4 1 2 3 4 ];
output = [ 1 1 1 1 2 2 2 2 3 3 3 3];
Thank you
0 commentaires
Réponse acceptée
Walter Roberson
le 14 Sep 2021
input = [ 1 2 3 4 1 2 3 4 1 2 3 4 ];
output = sum(triu(input' == input))
Plus de réponses (1)
KSSV
le 14 Sep 2021
input = [ 1 2 3 4 1 2 3 4 1 2 3 4 ];
a = reshape(input,[],3)' ;
[c,ia,ib] = unique(a,'rows') ;
ib
Voir également
Catégories
En savoir plus sur Calendar 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!