MATLAB  Logical Operations
MATLAB offers two types of logical operators and functions:
Elementwise  these operators operate on corresponding elements of logical arrays.
Shortcircuit  these operators operate on scalar, logical expressions.
Elementwise logical operators operate elementbyelement on logical arrays. The symbols &, , and ~ are the logical array operators AND, OR, and NOT.
Shortcircuit logical operators allow shortcircuiting on logical operations. The symbols && and  are the logical shortcircuit operators AND and OR.
Example
Create a script file and type the following code:
a = 5; b = 20; if ( a && b ) disp('Line 1  Condition is true'); end if ( a  b ) disp('Line 2  Condition is true'); end % lets change the value of a and b a = 0; b = 10; if ( a && b ) disp('Line 3  Condition is true'); else disp('Line 3  Condition is not true'); end if (~(a && b)) disp('Line 4  Condition is true'); end
When you run the file, it produces following result:
Line 1  Condition is true Line 2  Condition is true Line 3  Condition is not true Line 4  Condition is true
Functions for Logical Operations
Apart from the abovementioned logical operators, MATLAB provides the following commands or functions used for the same purpose:
Function  Description 

and(A, B)  Finds logical AND of array or scalar inputs; performs a logical AND of all input arrays A, B, etc. and returns an array containing elements set to either logical 1 (true) or logical 0 (false). An element of the output array is set to 1 if all input arrays contain a nonzero element at that same array location. Otherwise, that element is set to 0. 
not(A)  Finds logical NOT of array or scalar input; performs a logical NOT of input array A and returns an array containing elements set to either logical 1 (true) or logical 0 (false). An element of the output array is set to 1 if the input array contains a zero value element at that same array location. Otherwise, that element is set to 0. 
or(A, B)  Finds logical OR of array or scalar inputs; performs a logical OR of all input arrays A, B, etc. and returns an array containing elements set to either logical 1 (true) or logical 0 (false). An element of the output array is set to 1 if any input arrays contain a nonzero element at that same array location. Otherwise, that element is set to 0. 
xor(A, B)  Logical exclusiveOR; performs an exclusive OR operation on the corresponding elements of arrays A and B. The resulting element C(i,j,...) is logical true (1) if A(i,j,...) or B(i,j,...), but not both, is nonzero. 
all(A)  Determine if all array elements of array A are nonzero or true.

all(A, dim)  Tests along the dimension of A specified by scalar dim. 
any(A)  Determine if any array elements are nonzero; tests whether any of the elements along various dimensions of an array is a nonzero number or is logical 1 (true). The any function ignores entries that are NaN (Not a Number).

any(A,dim)  Tests along the dimension of A specified by scalar dim. 
false  Logical 0 (false) 
false(n)  is an nbyn matrix of logical zeros 
false(m, n)  is an mbyn matrix of logical zeros. 
false(m, n, p, ...)  is an mbynbypby... array of logical zeros. 
false(size(A))  is an array of logical zeros that is the same size as array A. 
false(...,'like',p)  is an array of logical zeros of the same data type and sparsity as the logical array p. 
ind = find(X)  Find indices and values of nonzero elements; locates all nonzero elements of array X, and returns the linear indices of those elements in a vector. If X is a row vector, then the returned vector is a row vector; otherwise, it returns a column vector. If X contains no nonzero elements or is an empty array, then an empty array is returned. 
ind = find(X, k)
ind = find(X, k, 'first')  Returns at most the first k indices corresponding to the nonzero entries of X. k must be a positive integer, but it can be of any numeric data type. 
ind = find(X, k, 'last')  returns at most the last k indices corresponding to the nonzero entries of X. 
[row,col] = find(X, ...)  Returns the row and column indices of the nonzero entries in the matrix X. This syntax is especially useful when working with sparse matrices. If X is an Ndimensional array with N > 2, col contains linear indices for the columns. 
[row,col,v] = find(X, ...)  Returns a column or row vector v of the nonzero entries in X, as well as row and column indices. If X is a logical expression, then v is a logical array. Output v contains the nonzero elements of the logical array obtained by evaluating the expression X. 
islogical(A)  Determine if input is logical array; returns true if A is a logical array and false otherwise. It also returns true if A is an instance of a class that is derived from the logical class. 
logical(A)  Convert numeric values to logical; returns an array that can be used for logical indexing or logical tests. 
true  Logical 1 (true) 
true(n)  is an nbyn matrix of logical ones. 
true(m, n)  is an mbyn matrix of logical ones. 
true(m, n, p, ...)  is an mbynbypby... array of logical ones. 
true(size(A))  is an array of logical ones that is the same size as array A. 
true(...,'like', p)  is an array of logical ones of the same data type and sparsity as the logical array p. 