Find the number of times each element in a vector is repeated, using MATLAB

1.8k Views Asked by At

Consider a vector in MATLAB, where some elements are repeated. For example $$v=[1 , 2, 7 , 8 ,3 ,2 ,8].$$ How can I find how many times each element in this vector is repeated without using a loop. Is there any MATLAB command for this?

1

There are 1 best solutions below

0
On BEST ANSWER

You can get the unique values (here $[1, 2, 3, 7, 8]$) with

u = unique(v)

then you can count how many times each of these values appear in $v$ with

histc(v, u)

Other ways are possible.