How to use use = logical operator on multiple values?

조회 수: 4 (최근 30일)
Koki
Koki 2020년 4월 21일
답변: Mohammad Sami 2020년 4월 21일
For example if I had vector A = [1,5,8,2,6,4,3];
And I want to check if A equal to 1st value, 2nd value or 4th value
istead of doing:
A1 = (A == A(1))| (A == A(2)) | (A == A(4))
Is there a shorter way, so like: A1 == A(1,2,4)
idk how to explain soz
  댓글 수: 2
Stephen23
Stephen23 2020년 4월 21일
Probably you could use ismember.
Ameer Hamza
Ameer Hamza 2020년 4월 21일
Koki, can you explain with a clear example. What does the statement "A equal to 1st value, 2nd value or 4th value" means? A is a vector, and its elements are scalar? How do you want to compare?

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

채택된 답변

Mohammad Sami
Mohammad Sami 2020년 4월 21일
As suggested by stephen, you can simply use ismember
A1 = ismember(A,A([1 2 4]));

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by