可以使用 hist 函数:
A = [1 2 8 8 1 8 2 1 8 2 1];count = hist(A,unique(A))
count 的结果与 unique(A) 对应.
来源: http://www.bubuko.com/infodetail-2987358.html