
- MATLAB - Home
- MATLAB - Overview
- MATLAB - Features
- MATLAB - Environment Setup
- MATLAB - Editors
- MATLAB - Online
- MATLAB - Workspace
- MATLAB - Syntax
- MATLAB - Variables
- MATLAB - Commands
- MATLAB - Data Types
- MATLAB - Operators
- MATLAB - Dates and Time
- MATLAB - Numbers
- MATLAB - Random Numbers
- MATLAB - Strings and Characters
- MATLAB - Text Formatting
- MATLAB - Timetables
- MATLAB - M-Files
- MATLAB - Colon Notation
- MATLAB - Data Import
- MATLAB - Data Output
- MATLAB - Normalize Data
- MATLAB - Predefined Variables
- MATLAB - Decision Making
- MATLAB - Decisions
- MATLAB - If End Statement
- MATLAB - If Else Statement
- MATLAB - If…Elseif Else Statement
- MATLAB - Nest If Statememt
- MATLAB - Switch Statement
- MATLAB - Nested Switch
- MATLAB - Loops
- MATLAB - Loops
- MATLAB - For Loop
- MATLAB - While Loop
- MATLAB - Nested Loops
- MATLAB - Break Statement
- MATLAB - Continue Statement
- MATLAB - End Statement
- MATLAB - Arrays
- MATLAB - Arrays
- MATLAB - Vectors
- MATLAB - Transpose Operator
- MATLAB - Array Indexing
- MATLAB - Multi-Dimensional Array
- MATLAB - Compatible Arrays
- MATLAB - Categorical Arrays
- MATLAB - Cell Arrays
- MATLAB - Matrix
- MATLAB - Sparse Matrix
- MATLAB - Tables
- MATLAB - Structures
- MATLAB - Array Multiplication
- MATLAB - Array Division
- MATLAB - Array Functions
- MATLAB - Functions
- MATLAB - Functions
- MATLAB - Function Arguments
- MATLAB - Anonymous Functions
- MATLAB - Nested Functions
- MATLAB - Return Statement
- MATLAB - Void Function
- MATLAB - Local Functions
- MATLAB - Global Variables
- MATLAB - Function Handles
- MATLAB - Filter Function
- MATLAB - Factorial
- MATLAB - Private Functions
- MATLAB - Sub-functions
- MATLAB - Recursive Functions
- MATLAB - Function Precedence Order
- MATLAB - Map Function
- MATLAB - Mean Function
- MATLAB - End Function
- MATLAB - Error Handling
- MATLAB - Error Handling
- MATLAB - Try...Catch statement
- MATLAB - Debugging
- MATLAB - Plotting
- MATLAB - Plotting
- MATLAB - Plot Arrays
- MATLAB - Plot Vectors
- MATLAB - Bar Graph
- MATLAB - Histograms
- MATLAB - Graphics
- MATLAB - 2D Line Plot
- MATLAB - 3D Plots
- MATLAB - Formatting a Plot
- MATLAB - Logarithmic Axes Plots
- MATLAB - Plotting Error Bars
- MATLAB - Plot a 3D Contour
- MATLAB - Polar Plots
- MATLAB - Scatter Plots
- MATLAB - Plot Expression or Function
- MATLAB - Draw Rectangle
- MATLAB - Plot Spectrogram
- MATLAB - Plot Mesh Surface
- MATLAB - Plot Sine Wave
- MATLAB - Interpolation
- MATLAB - Interpolation
- MATLAB - Linear Interpolation
- MATLAB - 2D Array Interpolation
- MATLAB - 3D Array Interpolation
- MATLAB - Polynomials
- MATLAB - Polynomials
- MATLAB - Polynomial Addition
- MATLAB - Polynomial Multiplication
- MATLAB - Polynomial Division
- MATLAB - Derivatives of Polynomials
- MATLAB - Transformation
- MATLAB - Transforms
- MATLAB - Laplace Transform
- MATLAB - Laplacian Filter
- MATLAB - Laplacian of Gaussian Filter
- MATLAB - Inverse Fourier transform
- MATLAB - Fourier Transform
- MATLAB - Fast Fourier Transform
- MATLAB - 2-D Inverse Cosine Transform
- MATLAB - Add Legend to Axes
- MATLAB - Object Oriented
- MATLAB - Object Oriented Programming
- MATLAB - Classes and Object
- MATLAB - Functions Overloading
- MATLAB - Operator Overloading
- MATLAB - User-Defined Classes
- MATLAB - Copy Objects
- MATLAB - Algebra
- MATLAB - Linear Algebra
- MATLAB - Gauss Elimination
- MATLAB - Gauss-Jordan Elimination
- MATLAB - Reduced Row Echelon Form
- MATLAB - Eigenvalues and Eigenvectors
- MATLAB - Integration
- MATLAB - Integration
- MATLAB - Double Integral
- MATLAB - Trapezoidal Rule
- MATLAB - Simpson's Rule
- MATLAB - Miscellenous
- MATLAB - Calculus
- MATLAB - Differential
- MATLAB - Inverse of Matrix
- MATLAB - GNU Octave
- MATLAB - Simulink
MATLAB - Array Division
MATLAB is a powerful programming language widely used for numerical computing, data analysis, and visualization. One of its fundamental operations is array division, which allows you to perform element-wise division on arrays and matrices.
Array Division
In MATLAB, array division is performed using the element-wise division operator (./). This operator allows you to divide corresponding elements of two arrays or matrices of the same size, creating a new array with the division results.
Syntax
result = array1 ./ array2;
Let us check the division of vectors and arrays in the examples below.
Division of Two Vectors
In this example, each element of vector1 is divided by the corresponding element of vector2, resulting in the array [5, 5, 5].
Example
vector1 = [10, 20, 30] vector2 = [2, 4, 6] result = vector1 ./ vector2
When you execute the same in matlab command window the output is −
vector1 = 10 20 30 vector2 = 2 4 6 result = 5 5 5
Division of Arrays
In the example we have matrix1 and matrix2. The operator (./) is used to divide matrix1 with matrix2. The result holds the output.
Example
matrix1 = [1, 2; 3, 4] matrix2 = [0.5, 1; 1.5, 2] result = matrix1 ./ matrix2
When you check the output in matlab command window the output is −
matrix1 = 1 2 3 4 matrix2 = 0.5000 1.0000 1.5000 2.0000 result = 2 2 2 2
rdivide() Method in Matlab for Division
MATLAB, a widely used programming language for numerical computation and data analysis, offers various built-in functions to simplify complex operations. One such function is rdivide(), performs element-wise division on arrays and matrices. In this article, we'll explore the rdivide() function, understand its functionality and go through the examples to understand how to make use of rdivide() on arrays and matrices.
The rdivide() function in MATLAB performs element-wise division of two arrays or matrices, similarly to the ./ operator. However, rdivide() simplifies the syntax and provides a more intuitive way to achieve the same result.
Syntax
result = rdivide(array1, array2);
Here are a few points that I came across that have advantages for using the rdivide() method.
- The syntax is simple and the use of the rdivide() function eliminates the need to explicitly use the ./ operator for element-wise division, making code more readable.
- The function's name conveys the division operation clearly, improving the clarity of your code.
Here are a few examples that you can try at your end.
Using rdivide() with Vectors
In the example below we have two vectors: vector1 with [10, 20, 30] and vector2 with [2,4,6]. The rdivide() method is used to divide vector1 with vector2.
Example
vector1 = [10, 20, 30] vector2 = [2, 4, 6] result = rdivide(vector1, vector2)
When you execute the above code in matlab command window the output is −
vector1 = 10 20 30 vector2 = 2 4 6 result = 5 5 5
Using rdivide() on Matrices
In the example below we have taken two matrices matrix1 and matrix2. The rdivide() function is used to divide matrix1 with matrix2.
Example
matrix1 = [1, 2; 3, 4] matrix2 = [0.5, 1; 1.5, 2] result = rdivide(matrix1, matrix2)
When the above code is executed in matlab command window the output is −
matrix1 = 1 2 3 4 matrix2 = 0.5000 1.0000 1.5000 2.0000 result = 2 2 2 2
Right Matrix Division Using mrdivide() and / Operator
The division operation can be performed using the / operator and the mrdivide() function. Here will understand the working of right matrix division and how to use the / operator and the mrdivide() function and also see a few examples on it.
Right Matrix Division with / Operator
Syntax
X = A/B
X = A/B performs right-matrix division.
Here A is Numerator and it can be scalar, vector or matrix.
B is a denominator and it can be a scalar , vector or matrix.
Let us see few examples.
Example 1
In the example below we are going to divide matrix A with matrix B.
A = [7, 8; 5, 6] B = [3, 2; 1, 4] X = A / B
On execution the output is −
A = 7 8 5 6 B = 3 2 1 4 X = 2.0000 1.0000 1.4000 0.8000
Example 2
Let us divide the matrix with a scalar value as shown below.
A = [7, 8; 5, 6] B = 2 X = A/B
When you execute the same in matlab command window the output is −
A = 7 8 5 6 B = 2 X = 3.5000 4.0000 2.5000 3.0000
Using mrdivide() Method
The mrdivide() function is an alternative way to perform right matrix division. It allows you to explicitly use the division syntax and is especially useful when dealing with complex equations involving matrices.
Syntax
X = mrdivide(A, B)
The above syntax is the same as A/B.
Let us test few examples using mrdivide()
Example
In the example below we have two matrices A1 and B1. The output of A1/B1 is done using mrdivide() method.
A1 = [2, 3, 1; 0, 8, 4; 1, 1, 0] B1 = [7, 6, 6; 1, 0, 5; 9, 0, 4] X = mrdivide(A1,B1)
When you execute the same in matlab command window the output is −
A1 = 2 3 1 0 8 4 1 1 0 B1 = 7 6 6 1 0 5 9 0 4 X = 0.5000 -0.2927 -0.1341 1.3333 0.0325 -1.0407 0.1667 -0.2033 0.0041