简体   繁体   English

矩阵每一行中的正数(> 0)数

[英]Number of the positive (> 0) values in each row of a matrix

Considering A = a 100 by 5 matrix of random integers between 􀀀-100 and 100, I would like to find B = the number of the positive (>= 0) values in each row of A using sum (no loops). 考虑A =介于-100到100之间的100个5随机整数矩阵,我想使用和(无循环)在A的每一行中找到B =正值(> = 0)的数量。

B=sum(rint(:)>0) does not seem right as it only gives me the total number of positive values of the whole matrix. B=sum(rint(:)>0)似乎不正确,因为它只给我整个矩阵的正值总数。

How do I get the values for each row? 如何获得每一行的值?

Thank you! 谢谢!

You can use B=sum(rint>0) to get the sum of the columns, and B=sum(rint>0,2) to get the ones of the row. 您可以使用B=sum(rint>0)来获取列的总和,并使用B=sum(rint>0,2)来获取行的B=sum(rint>0,2) Sum accepts a second argument to define the dimension on which you are summing. Sum接受第二个参数来定义要求和的维。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM