Indeed, there is a general approach. You can use the any function to check if x matches any of the elements in the array:
if any(x == [5, 6]) % execute code end
This works for numeric arrays. If you are working with cell arrays you can use ismember (thanks @ nilZ0r!)
choices = {'foo', 'bar', 'hello'}; x = 'hello'; if ismember(x, choices) % execute code end
ismember works for both numeric and array of cells (thanks @TasosPapastylianou).
source share