matlab找出两个矩阵不同的元素,求Matlab矩阵中各个不同元素或者某个元素出现的次数...

本文介绍了如何在Matlab中使用`tabulate`函数来统计矩阵中不同元素出现的次数及其占比。通过示例展示了如何针对不同矩阵进行操作,并且提到了`numel`函数用于计算元素的数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.求矩阵中各个不同的元素出现的次数

tabulateFrequency 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值