matlab的:从两个数组相同的项目找到共同的价值观的指数 [英] matlab: find the index of common values at the same entry from two arrays

查看:163
本文介绍了matlab的:从两个数组相同的项目找到共同的价值观的指数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有大小两个数组 P P 是大)有从<$ C值$ C> 0,1,2 。我正在寻找一种方式来找到这两个阵列具有值 2 在同一条目索引,一个具有价值指数 2 ,另一个具有价值 1 等(如 2 2 2 1 `2 0 1 1 1 0`)。

Suppose that I have two arrays of size p (p is large) that have values from 0,1,2. I am looking for a way to find the index that both arrays have value 2 at the same entry, the index that one has value 2 and the other one has value 1, etc (like 2 and 2, 2 and 1, `2 and0,1and1,1and0`).

有没有办法实现这一目标,而无需使用for循环的 P

Is there a way to achieve this without using the for loop on p?

推荐答案

您可以使用逻辑阵列,让 A B 是你的数组(大小一致):

You can use logical arrays, let A and B be your arrays (with consistent sizes):

Indices=find((A==2)&(B==2));

等。其他操作。

请注意,如果 A B 有尺寸大于1,指数将是一个线性的指数,改为 [X,Y] =找到((A == 2)及(B == 2)); 如果你想要行/列对。

Note that if A and B have dimensions higher than 1, Indices will be a linear index, change to [x,y]=find((A==2)&(B==2)); if you want row/column pairs.

这篇关于matlab的:从两个数组相同的项目找到共同的价值观的指数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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