Comparing two vectors with different dimensions

1 次查看(过去 30 天)
Hello,
How can you compare two vectors with different number of elements? I am just trying to find the equal elements. Thanks!

采纳的回答

the cyclist
the cyclist 2012-6-14
Your question is fairly vague, but I have a feeling that either the ismember() command or the intersect() command will help you do what you want.
  1 个评论
osminbas
osminbas 2012-6-14
Sorry I wasn't clearer. And yes, intersect was what I was looking for. Thank you!

请先登录,再进行评论。

更多回答(1 个)

Rohan Kale
Rohan Kale 2012-6-19
Let a and b be two arrays(or vectors). L=length(a), M=length(b).Suppose L>M, pad_zero=L-M; now b=[b zeros(1,pad_zero)]; c=a-b; now you can find the indices of the zero elements excluding the last pad_zero elements. These are your desired indices. Hope it helps.
  2 个评论
the cyclist
the cyclist 2012-6-19
Uh ... isn't it a lot easier to just use [c ia ib] = intersect(a,b)?
Rohan Kale
Rohan Kale 2012-6-19
yes it is indeed, I was just trying out an alternative....

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by