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

1 visualización (últimos 30 días)
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!

Respuesta aceptada

Cedric
Cedric el 21 de Oct. de 2013
Editada: Cedric el 21 de Oct. de 2013
if A~=8 && A~=12 && A~=16
error('..','...') ;
end
you could also use ISMEMBER:
if ~ismember(A, [8, 12, 16])
error('..','...') ;
end

Más respuestas (0)

Categorías

Más información sobre Signal Generation and Preprocessing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by