Hi,
I am trying to generate an if condition by comparing an value with a whole vector of values. If any is true, the if condition should execute.
In this example g should be true:
a = [1 2 3 4 5];
b = [8 9 10];
c = 10;
if c == a(:) || c == b(:)
g = true;
else
g = false;
end
I am sure there is a simple solution, I just dont know it.
Thanks everyone!

 채택된 답변

Alan Stevens
Alan Stevens 2021년 2월 10일

1 개 추천

Use ismember
a = [1 2 3 4 5];
b = [8 9 10];
c = 10;
if ismember(c,a)||ismember(c,b)
g = "true";
else
g = "false";
end
disp(g)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

태그

질문:

2021년 2월 10일

댓글:

2021년 2월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by