Octave Subtraction Operator
Octave Subtraction Operator
In this tutorial, you will learn about the Octave Subtraction Operator with Examples. The subtraction operator in Octave is minus (-). The – operator is a binary operator. It requires two operands for mathematical computation. The operands can be scalars or matrices.
Examples
Subtracting scalar operands
If the operands are scalars, the subtraction operator subtracts them. Here, in this example, x and y are scalar operands. We use the – operator to subtract and store the result in a variable called result.
>> x = 9;
>> y = 7;
>> result = x – y;
>> result
result = 2
Subtracting matrices
If the operands are matrices, the number of rows and columns must agree or be broadcastable.
We can use the .- operator for the element-wise subtraction of the matrices.
>> x = [ 5 6 ; 7 8];
>> y = [ 2 4 ; 5 6];
>> result = x .- y ;
>> result
result =
3 2
2 2
—
Octave Tutorials
GNU Octave Tutorials on this website can be found at:
For more information on Octave, visit the official website: