The standard way to compute the number of unique entries in a matlab matrix
If our entries are positive integers, we can try to do the same thing using
but actually this is slower.
I don’t see a way to avoid a sort. I came up with this,
As far as I can tell, this will work for matrices that don’t have infs and nans. It’s slightly faster than
number(unique(A)). I have a feeling I’m only winning anything here because I’m avoiding overhead within