UNIQUE を使用して要素の重複​回数を数えることは可​能ですか?

14 visualizaciones (últimos 30 días)
MathWorks Support Team
MathWorks Support Team el 18 de Oct. de 2013
Respondida: MathWorks Support Team el 18 de Oct. de 2013
UNIQUE 関数を使用して、配列内で要素が何回出てきているか数える方法を教えてください。

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 18 de Oct. de 2013
MATLAB の UNIQUE 関数には各ユニークな要素の数を数える機能はありません。この問題を解決するには、ARRAYFUN を使用して各要素が元のベクトルの要素に等しい数を決定する配列の各要素を調べます。
例:
a = [12 34 78 8 12 3 34 34];
c = arrayfun(@(x)length(find(a == x)), unique(a), 'Uniform', false);
cell2mat(c)

Más respuestas (0)

Categorías

Más información sobre table en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!