Filter löschen
Filter löschen

comment je peux compacter un tableau

1 Ansicht (letzte 30 Tage)
SOLTANI BILLAL
SOLTANI BILLAL am 19 Okt. 2019
Beantwortet: Ankit Kumar am 23 Okt. 2019
bonjour je veux savoir comment je peux compter le nombre de répétition d'un nombre entier dans un vecteur
T=[3.1 3.1 3.1 3.1 3.6 3.6 3.4 3.3 3.2 3.2 3.2 3.0 3.0]
et je veux qu'il m'affiche
T=[3.1 4 3.6 2 3.4 1 3.3 1 3.2 3 3 2]

Antworten (1)

Ankit Kumar
Ankit Kumar am 23 Okt. 2019
Hi,
Vous pouvez extraire les valeurs uniques par,
A = val = unique(T,'stable');
Vous pouvez compter le nombre d'occurrences par,
B = sum(bsxfun(@eq,val,T(:)));
Il suffit de combiner les deux tableaux pour obtenir le résultat

Community Treasure Hunt

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

Start Hunting!