MATLAB OperatorAn operator is a symbol that tells the compiler to perform various numerical or logical manipulations. MATLAB is designed to operate mainly on whole matrices and arrays. Therefore, functions in MATLAB work both on scalar and nonscalar data. MATLAB has several types of operators, symbols, and special characters to deal with variables, functions, and arithmetic operations. MATLAB Arithmetic OperatorsArithmetic operators help in performing simple arithmetic operations like addition, subtraction, multiplication, division, and power.
Arithmetic Operators and ArraysExcept for some matrix operators, MATLAB arithmetic operators work on corresponding functions of arrays with equal dimensions. For vectors and rectangular array, both operands must be the equivalent size unless one is a scalar. If one operand is a scalar and the other is not, MATLAB applies the scalar to every item of the other operand, this property is called scalar expansion. This example uses scalar expansion to evaluate the product of a scalar operand and a matrix. MATLAB Relational OperatorsRelational operators perform value comparison operations.
Relational Operators and ArraysThe MATLAB relational operators compare corresponding components of arrays with equal dimensions. Relational operators always operate elementbyelement. In this example, the resulting matrix present where the element of A is equal to the corresponding part of B. For vectors and rectangular array, both operands must be the same size unless one is a scalar. In this case, where one operand is a scalar, and the other is not, MATLAB tests the scalar against every element of the other operand. Locations where the particular relation is true receive logical 1. Locations where the relation is false receive logical 0. MATLAB Logical OperatorsLogical operators perform logical operations and output the result in Boolean state true or false using the numbers 1 and 0, respectively. MATLAB offer three types of logical operators and functions:
The values returned by MATLAB logical operators and functions, with the exception of bitwise functions, are of type logical and are suitable for use with logical indexing. ElementWise Operators and FunctionsThe following logical operators and functions execute elementwise logical operations on their inputs to produce a likesized output array. The examples are shown in the following table use vector inputs A and B, where A = [0 1 1 0 1];
For operators and functions that take two array operands (&, , and xor), both arrays must have the same dimensions, with each dimension being the same size. The one exception to this is where one operand is a scalar, and the other is not. Note: MATLAB converts any finite nonzero, mathematic values used as inputs to logical expressions to logical 1, or true.BitWise OperatorThe following functions execute bitwise logical operations on nonnegative integer inputs. Inputs may be scalar or in arrays. If in arrays, these operations produce a likesized output array. The examples are present in the following table use scalar inputs A and B, where A = 28; % binary 11100
ShortCircuit OperatorsThe following operators execute AND and OR operations on logical expressions, including scalar values. They are shortcircuiting operators in that they calculate their second operand only when the first operand does not fully determine the output.
MATLAB Special CharactersSpecial characters perform some particular tasks according to their behavior and the position where they are used.
MATLAB String and Character Formatting Special CharactersThere are some special characters to use only within the text of a character or string. These special characters are used to insert newlines or carriage returns, specify folder paths.
Next TopicFormatting Text
