Matching Two Numeric Vectors
이전 댓글 표시
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
2019년 6월 8일
0 개 추천
The ismembertol (link) function is likely appropriate. (Another option is the ismember (link) function, althoughit is likely not appropriate here.)
댓글 수: 6
Patrick Rungrugeecharoen
2019년 6월 8일
Star Strider
2019년 6월 8일
The first output of either function is a logical vector. You can then use the and,& (link) function to logically ‘and’ the two vectors with a logical vector testing ‘C’. The & of those vectors will produce a logical vector describing ‘D’.
Patrick Rungrugeecharoen
2019년 6월 8일
Star Strider
2019년 6월 8일
I got the impression that all three vectors, ‘A’. ‘B’ and ‘C’ were the same length. If that is not true, then you can only match the elements that correspond to the shortest vector.
Patrick Rungrugeecharoen
2019년 6월 8일
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.
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!