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?
Asked
Active
Viewed 1,840 times
1 Answers
2
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.
Giovanni Resta
- 2,368