识别矩阵中的值 [英] Identifying value in matrix

查看:72
本文介绍了识别矩阵中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到问题,然后需要您的帮助来解决.

I have a problem and then I need your help to solve it.

我有一个矩阵A

A = [ 0 0 1 2 3 4 0;
      1 2 3 4 0 0 0;
      0 0 0 1 2 3 4;
      0 1 2 3 4 0 0]

然后我想知道矩阵A中每行的每个值"1"有多少个,不在同一列中,矩阵A中每行的每个值> = 3".

and then I want to know how many number of each values "1" of each rows in matrix A which is not in the same column with each value ">=3" of each rows in matrix A.

所以我希望我的回答

Ans = 2

谢谢.

推荐答案

尝试一下:

>> num = sum( any(A(:,all(A<3))==1,2) )
num =
     2

首先,我们找到不包含大于或等于3 idx = all(A<3)的值的列索引.

First we find the columns indices containing no values greater or equal to 3 idx = all(A<3).

接下来在这些列A(:,idx)中,我们找到包含任意1的行:any(A(:,idx)==1,2).

Next in those columns A(:,idx), we find the rows containing any 1: any(A(:,idx)==1,2).

最后,我们计算发现了多少这样的行sum(.)

Finally we count how many such rows were found sum(.)

这篇关于识别矩阵中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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