Unique values per row
Show older comments
Hi all, I'm struggling to figure a simple method to determine the number of unique values per row in a matrix. For example in the matrix [1 2 3; 4 4 5; 6 6 6]
I would expect the result to be [3, 2, 1] I've tried using unique() and histc but neither are giving me the result I am looking for. Thanks!
Accepted Answer
More Answers (1)
Walter Roberson
on 4 Nov 2018
There is a vectorized way to compute this but it is not simple and it quickly gets expensive to calculate. Easier is
cellfun(@(c) length(unique(c)), num2cell(YourMatrix, 2))
1 Comment
Zee Imports
on 6 Nov 2018
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!