1.求矩阵中各个不同的元素出现的次数
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 =
1 2 3 4
5 3 5 2
5 6 7 7
>> t=tabulate(a(:))
t =
1.0000 1.0000 8.3333
2.0000 2.0000 16.6667
3.0000 2.0000 16.6667
4.0000 1.0000 8.3333
5.0000 3.0000 25.0000
6.0000 1.0000 8.3333
7.0000 2.0000 16.6667
>> a
a =
>> aa = tabulate(a(:))
aa =
2.求矩阵中某个元素出现的次数
N = numel(A) returns the number of elements, N, in array A, equivalent
to PROD(SIZE(A)).
>> N=numel(find(c==5))
N =
0