Matching Two Numeric Vectors

10 次查看(过去 30 天)
I have for instance a vector called A:
And another vector called B:
And another vector called C:
I'd like another vector D which is:
  • same length as vector B and C; and
  • will show a 1 if:
  • there is a match between vector A and vector B (else a 0); and
  • the corresponding matched value in vector C is less than or equal to 30.
For instance:
B(1) = 149.1408, A(1) = 149.1408, C(1) = 5 <= 30 so D(1) = 1 etc etc.
Would also like a vector E (size of A) counting occurrences from vector D.

回答(1 个)

Star Strider
Star Strider 2019-6-8
The ismembertol (link) function is likely appropriate. (Another option is the ismember (link) function, althoughit is likely not appropriate here.)
  6 个评论
Patrick Rungrugeecharoen
Yes, hence the little pickle I'm in. Not too sure how to resolve this issue. I figured two for loops would work but it stops at the shorter of the two.
Star Strider
Star Strider 2019-6-8
You actually don’t need any loops. You can do everything with the logical vectors.
You have to choose how to deal with the vectors not having the same numbers of elements. I can’t resolve that.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by