If statement with OR operator to create error message for a function

조회 수: 1 (최근 30일)
LivingTheScienceDream
LivingTheScienceDream 2013년 10월 21일
편집: Cedric 2013년 10월 21일
Hi
I have a function that has a second input that must be 8, 12 or 16. I want to have an error message to flag when the 2nd input does not take these values. I have tried doing this in an if statement:
if A~=8 || A~=12 || A~=16
error('..','...')
end
Of course, I think my logic here is wrong (if the input is 12, it is true for the A~=8 or 16) and so the if statement is always true and can never be false. Would an AND/OR work (if these exist in matlab)?
Is there a way I can do this in an if statement? Or is there a better way of writing what I'm trying to do?
Thanks for your help!

채택된 답변

Cedric
Cedric 2013년 10월 21일
편집: Cedric 2013년 10월 21일
if A~=8 && A~=12 && A~=16
error('..','...') ;
end
you could also use ISMEMBER:
if ~ismember(A, [8, 12, 16])
error('..','...') ;
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Signal Generation and Preprocessing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by