필터 지우기
필터 지우기

comment je peux compacter un tableau

조회 수: 1 (최근 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!