Can I use UNIQUE to get a count of the number of times each element is repeated?
219 views (last 30 days)
The ability to return the count of each unique element is not available in the UNIQUE function in MATLAB.
To work around this issue, use the ARRAYFUN function to test each element of an array, determining the number of times each element is equal to an element of original vector.
a = [12 34 78 8 12 3 34 34];
c = arrayfun(@(x)length(find(a == x)), unique(a), 'Uniform', false);