Matlab,如何比较行矩阵的每个元素和另一个行矩阵的每个元素? [英] Matlab, How do I compare each element of a row matrix with each element of another row matrix?

查看:98
本文介绍了Matlab,如何比较行矩阵的每个元素和另一个行矩阵的每个元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Matlab中有两个矩阵:

I have two matrices in Matlab:

q = [3 4 5];  
w = [5 6 7];

我想比较qw的每个元素(即3与5、6和7进行比较).如果它与w中的任何元素匹配(例如qw中的5都一样),则qw都将5用作公用密钥.

I want to compare every element of q with w (i.e. 3 compared with 5, 6, and 7). If it matches any element in w (like how 5 is in both q and w) then both q and w share 5 as a common key.

如何计算qw的所有公用密钥?

How can I compute all the common keys for q and w?

推荐答案

尝试

>> x = intersect(q,w)

x = 

    5

此函数将输入向量视为集合,并返回集合交点.我想这就是您想知道的.是否有匹配项?如果x为空(numel(x)== 0),则没有匹配项.

This function treats the input vectors as sets and returns the set intersection. I think this is what you wanted to know. Is there a match yes/no? if x is empty (numel(x)==0) there was no match.

这篇关于Matlab,如何比较行矩阵的每个元素和另一个行矩阵的每个元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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