如何计算矩阵中给定值的元素数量? [英] How can I count the number of elements of a given value in a matrix?

查看:107
本文介绍了如何计算矩阵中给定值的元素数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何计算一个值出现在矩阵中的次数吗?



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

解决方案 http://www.mathworks.com/matlabcentral/fileexchange/23333-determine-and-count-unique-values-of-an-array =nofollow noreferrer>确定和计数数组的唯一值< a>。





或者,要计算 5 的出现次数,只要做

  sum(your_matrix == 5)


Does anyone know how to count the number of times a value appears in a matrix?

For example, if I have a 1500 x 1 matrix M (vector) which stores the values of weekdays (1 - 7), how could I count how many Sundays (1), Mondays(2), ... , Saturdays(7) are stored in M?

解决方案

Have a look at Determine and count unique values of an array.

Or, to count the number of occurrences of 5, simply do

sum(your_matrix == 5)

这篇关于如何计算矩阵中给定值的元素数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆