Lets say that I have these vectors
v1=[2 4 1 4]
v2=[1 3 3 4]
v3=[2 6 9 5]
and I wan't to find all the vectors that have any of these numbers
nmbr=[2 5 9]
which whould give med v1 and v3 How would i solve this?

 채택된 답변

Wan Ji
Wan Ji 2021년 8월 23일
편집: Wan Ji 2021년 8월 23일

0 개 추천

any(ismember(v1, nmbr))
any(ismember(v2, nmbr))
any(ismember(v3, nmbr))
If true, then the vector has any of these numbers [2 5 9]

댓글 수: 3

Wan Ji
Wan Ji 2021년 8월 23일
So you see the answer is true, false, and true. v1 and v3 are satisfied
Sebastian Daneli
Sebastian Daneli 2021년 8월 23일
Thank you
You can also do by combining v1,v2,and v3
v1=[2 4 1 4];
v2=[1 3 3 4];
v3=[2 6 9 5];
V = [v1', v2', v3']; % each column represents a vector
nmbr=[2 5 9];
p = ismember(V,nmbr);
result = find(any(p))
The answer is
result =
1 3
So v1 and v3 are satisfied

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2021년 8월 23일

댓글:

2021년 8월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by