You are on page 1of 16

Relational Operations

There are six relational operations in


MATLAB
• These operations result in a vector or matrix of the same size as the
operands, with 1 where the relation is true and 0 where it is false.
• Example:
Although these operations are usually used in conditional statements such as if-
then-else to branch out to different cases.
Logical operations
• There are four logical operators:
• & logical AND
• | logical OR
• ~ logical compliment (NOT)
• xor exclusive OR
• These operations work in a similar way as the relational operators and
produce vectors or matrices of the same size as the operand, with 1
where the condition is true and 0 where false.
Consider the following truth tables:
AND TABLE NOT TABLE

OR TABLE XOR TABLE


Example: For two vectors
• Since the output of the logical operations is a 0-1 vector or 0-1 matrix,
the output can be used as the index of a matrix to extract appropriate
elements. For example, to see those elements of x that satisfy both
the conditions (x > y) & (x > 4) , type x((x > y) & (x > 4))
In addition to these logical operators, there are
many useful built-in logical functions, such as:
•all true (=1) if all elements of a vector are true.
•any true (=1) if any elements of a vector are true.
•exist true(=1) if the argument exists.
•isempty true (=1) for an empty matrix
•isinf true for all infinite elements of a matrix.
•isfinite true for all finite elements of a matrix
•isnan true for all elements of a matrix that are not a number.
•find finds indices of non-zero elements of a matrix.
Examples:
Examples:
Elementary math functions
• sin Sine function
• asin Inverse sine function
• tan Tangent function
• atan, atan2 Inverse tangent function
Example:
Thank you so much

You might also like