필터 지우기
필터 지우기

How can I count the occurrences of each element in a column vector and store them in a vector of the same dimension as the original one?

조회 수: 3 (최근 30일)
Hi, I have a vector A mx1 and I want to create a vector B mx1 reporting the number of occurrences of each element in A, e.g. if
A=[1;2;2;3;4;2;5;6;7;8;8];
then
B=[1;3;3;1;1;3;1;1;1;2;2];
I prefer not to use loops because actual vectors have very high dimensions.

채택된 답변

Roger Stafford
Roger Stafford 2013년 11월 29일
[c,ix] = histc(A,unique(A));
B = c(ix);

추가 답변 (1개)

dpb
dpb 2013년 11월 29일
N=histc(A,unique(A));
B=N(A);

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by