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 = [2 4 6 8;3 5 6 3; 9 8 5 3; 7 6 4 0];
>> a
a =
2 4 6 8
3 5 6 3
9 8 5 3
7 6 4 0
>> aa = tabulate(a(:))
aa =
0 1.0000 6.2500
2.0000 1.0000 6.2500
3.0000 3.0000 18.7500
4.0000 2.0000 12.5000
5.0000 2.0000 12.5000
6.0000 3.0000 18.7500
7.0000 1.0000 6.2500
8.0000 2.0000 12.5000
9.0000 1.0000 6.2500
2.求矩阵中某个元素出现的次数
numel Number 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