comment je peux compacter un tableau

2 ビュー (過去 30 日間)
SOLTANI BILLAL
SOLTANI BILLAL 2019 年 10 月 19 日
回答済み: Ankit Kumar 2019 年 10 月 23 日
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]

回答 (1 件)

Ankit Kumar
Ankit Kumar 2019 年 10 月 23 日
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!