Operators#

Arithmetic operators#

Operator

Description

Example

+

Addition

a + b Adds a and b.

-

Subtraction

a - b Subtracts b from a.

*

Matrix Multiplication

a * b Multiplies a and b if a and b are matrices or vectors. If either operand is a scalar, element-by-element multiplication will be performed.

.*

ExE Multiplication

a .* b Multiplies elements of a and b.

`.*. `

Kronecker Product

a .*. b Computes the Kronecker (tensor) product of a and b.

/

Matrix Division

a / b Computes the least squares solution if a and b are matrices or vectors. If either operand is a scalar, element-by-element division will be performed.

./

ExE Division

a ./ b Divides each element of a by the corresponding element of b.

.^

ExE Power

a .^ b Raises each element of a to the power of b.

Factorial

n! Computes the factorial of n.

%

Modulo

a % b Computes the remainder of a divided by b.

'

Transpose

a' Transposes matrix a, swapping its rows with columns.

.'

Bookkeeping Transpose

a.' Transposes matrix a without conjugation, applicable to complex matrices.

=

Assignment

a = b Assigns b to a.

:

Range

a:b Creates a sequence from a to b. a:step:b creates a stepped sequence. Inside brackets, creates an index range for slicing.

|

Vertical Concatenation

a | b Vertically concatenates a and b (stacks rows).

~

Horizontal Concatenation

a ~ b Horizontally concatenates a and b (appends columns).

String operators#

Operator

Description

Example

$+

String Combine

a $+ b Combines strings element-by-element.

$|

String Vertical Concatenation

a $| b Vertically concatenates string arrays.

$~

String Horizontal Concatenation

a $~ b Horizontally concatenates string arrays.

Relational operators#

Operator

Description

Example

.==

Element-by-Element Equality

a .== b Compares each element of a with b, resulting in a matrix of 1’s and 0’s.

==

Equality

a == b Returns a scalar 1 (true) if all elements of a and b are equal, otherwise 0 (false).

=

Inequality

a != b Returns a scalar 1 (true) if a and b are not equal, otherwise 0 (false).

.!=

Element-by-Element Inequality

a .!= b Compares each element of a with b, resulting in a matrix of 1’s and 0’s.

>

Greater Than

a > b Returns 1 (true) if all elements of a are greater than those of b.

.>

Element-by-Element Greater Than

a .> b Compares each element of a with b, resulting in a matrix of 1’s and 0’s.

.>=

Element-by-Element Greater or Equal

a .>= b Compares each element of a with b, resulting in a matrix of 1’s and 0’s.

>=

Greater or Equal

a >= b Returns 1 (true) if all elements of a are greater than or equal to those of b, otherwise 0 (false).

<

Less Than

a < b Returns 1 (true) if all elements of a are less than those of b.

.<

Element-by-Element Less Than

a .< b Compares each element of a with b, resulting in a matrix of 1’s and 0’s.

.<=

Element-by-Element Less or Equal

a .<= b Compares each element of a with b, resulting in a matrix of 1’s and 0’s.

<=

Less or Equal

a <= b Returns a scalar 1 (true) if all elements of a are less than or equal to those of b, otherwise 0 (false).

Logical operators#

Operator

Description

Example

not

Logical NOT

not a Returns logical negation of a.

and

Logical AND

a and b Returns 1 if both a and b are true (non-zero).

or

Logical OR

a or b Returns 1 if either a or b is true (non-zero).

xor

Logical XOR

a xor b Returns 1 if exactly one of a or b is true.

eqv

Logical EQV

a eqv b Returns 1 if a and b have the same logical value.

Other operators#

Operator

Description

Example

&

Address/Pointer

&x Returns the address of variable x for use with function pointers.

^

String Dereference

^varname Substitutes the value of a string variable in commands that expect literal strings.