求Matlab矩阵中各个不同元素或者某个元素出现的次数

1.求矩阵中各个不同的元素出现的次数 【求Matlab矩阵中各个不同元素或者某个元素出现的次数】 tabulate Frequency table.
TABLE = tabulate(X) takes a vector X and returns a matrix, TABLE.
The first column of TABLE contains the unique values of X.The
second is the number of instances of each value.The last column
contains the percentage of each value.

举例
>> a=[1,2,3,4; 5,3,5,2; 5,6,7,7]
a =
1234
5352
5677
>> t=tabulate(a(:))
t =
1.00001.00008.3333
2.00002.000016.6667
3.00002.000016.6667
4.00001.00008.3333
5.00003.000025.0000
6.00001.00008.3333
7.00002.000016.6667

>> a = [2 4 6 8; 3 5 6 3; 9 8 5 3; 7 6 4 0];
>> a
a =
2468
3563
9853
7640
>> aa = tabulate(a(:))
aa =
01.00006.2500
2.00001.00006.2500
3.00003.000018.7500
4.00002.000012.5000
5.00002.000012.5000
6.00003.000018.7500
7.00001.00006.2500
8.00002.000012.5000
9.00001.00006.2500


2.求矩阵中某个元素出现的次数 numelNumber of elements in an array or subscripted array expression.
N = numel(A) returns the number of elements, N, in array A, equivalent
to PROD(SIZE(A)).

举例
>> N=numel(find(c==5))


N =


0

    推荐阅读