In this situation, accumarray will be faster than histcounts, but still not as fast as the for-loop,
Elapsed time is 0.172890 seconds.
Elapsed time is 0.236013 seconds.
unless the values are pre-sorted,
Elapsed time is 0.168976 seconds.
Elapsed time is 0.075965 seconds.
I think this is simply one of those situations where Matlab's for-loop optimization has caught up to vectorized code.