Matlab比较不同大小的向量 [英] Matlab compare different sized vectors
本文介绍了Matlab比较不同大小的向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有2个向量:A具有n个元素,B具有m个元素,且m< n
If I have 2 vectors: A with n elements and B with m elements and m < n,
如何在不使用for循环的情况下识别A中位于B中的所有元素?
how do I identify all the elements in A which are in B, without using a for loop?
非常感谢
推荐答案
C = intersect(A,B)
将为您提供两者中的所有元素.
C = intersect(A,B)
will give you all the elements which are in both.
还有ismember(A,B)
,它将返回逻辑数组,指示A的每个成员是否也是B的成员.
There's also ismember(A,B)
, which will return a logical array indicating for each member of A whether it is also a member of B.
这篇关于Matlab比较不同大小的向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文