%Boolean algebra clear %clears everything. clc %clears the screen x = 10; %Now x = 10. y = 1; %Guess what y is equal to. %What if we test ~(x < 2) ? ~(x < 2) %x < 2 is false, so its negation is true... %What if we test (x > 2)&(y<1) ? (x>2)&(y<1) %It is false since (y<1) is false... %But if we test (x>2)&(y>0) : (x>2)&(y>0) %Both are true, so the result is true. %Now what if we test (x > 2)||(y<1) ? (x > 2)||(y<1) %It is now true since only one is required to be true for %the or operator... %With this, we can already look at the next part : flow control with the if %operator. %Assume we want to perform some task only if x is positive. We could then %have : if( x >= 0 ) %If x is greater or equal than zero... %Begin conditionnal code disp('I will execute all the code between those lines'); disp('I could do many lines of stuff'); disp('And then some !'); %End conditionnal code else %Begin the code if x is not greater or equal than zero. disp('If x is greater or equal than zero, this will never be printed !'); %End the code if x is not greater or equal than zero. end %End of the if statement. disp('I am done now. Bye bye !');