MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何计算矩阵中给定值的元素数量? (https://www.labfans.com/bbs/showthread.php?t=23460)

poster 2019-12-10 20:41

如何计算矩阵中给定值的元素数量?
 
有谁知道如何计算一个值出现在矩阵中的次数?

例如,如果我有一个1500 x 1矩阵M (向量),用于存储工作日(1-7)的值,那么我如何计算多少个星期日(1),星期一(2),...,星期六(7) )存储在M ?



[B]回答:[/B]

看一下[URL="http://www.mathworks.com/matlabcentral/fileexchange/23333-determine-and-count-unique-values-of-an-array"]确定并计算数组的唯一值[/URL] 。

或者,要计算5的出现次数,只需执行

sum(your_matrix == 5)

[url=https://stackoverflow.com/questions/2880933]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 01:09

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.