Oldest question in the history of humanity…
If the number is even, the remainder after the division by 2 is zero, and 1 if the number is odd, so using rem function (which actually calculates the remainder of the division between two numbers) in matlab we can check if remainder is zero or not.
Example: If my var is MyVar,
rem(MyVar,2)=0 if MyVar is even
rem(MyVar,2)=1 if MyVar is odd
If I want to do something if my variable is even (or odd), I can write: