Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Logical Operations

MATLAB commands Operation

Assuming both ‘a’ and ‘b’ have Boolean values ( 1 or 0)

c=a|b Logical OR
c=a&b Logical AND
c= ~a Logical NOT
C= xor(a,b) Logical XOR

The same logical operations can also be done with arrays.


Examples:

MATLAB Instructions Result


a = 1;
b = 0;
c = 0;
d= a|c >>1
e = b|c >>0
f = a&b >>0
e = a&d >>1
g = ~a >>0
h = xor(a,b) >>1
a=[1 0 1];
b=[0 0 1];
c=a|b >>[ 1 0 1]
c=a&b >>[ 0 0 1]
c=~b >>[ 1 1 0]
c=xor(a,b) >>[1 0 0]

You might also like