MATLAB is a high-level language and interactive environment for numerical computation and visualization. It has a variety of functions for complex formulation; like finding the imaginary part of a complex number using the img() function or using the conj() function to calculate the conjugate value of a complex number. You can also utilize MATLAB functions to calculate the permute array dimension in MATLAB quite effectively.
What is Permute
In Mathematics, the word permute is an abbreviation of permutation that means modifying the arrangement of objects in a specific order or it also refers to the act or process of changing the linear order of an order set. In a matrix or an array, you can change the rows and columns through permutation which can be useful for varieties of tasks, such as sorting, cryptography, and finding patterns.
How to Permute Array Dimensions in MATLAB
In MATLAB, you can use the permute() function to shuffle the elements according to your desire. This function uses the two arguments as input; the first one is the matrix or an array and the second one is the order specified by the vector dimorder.
Syntax
The syntax for using the permute() function in MATLAB is given below:
Where A is the matrix or an array, dimorder is a vector of integers that specifies the new order of the dimensions of the matrix or array (switches the rows and columns dimension), while B is the permuted matrix or an array.
Examples
Let’s consider the following examples that use the permute() function to permute array dimensions in MATLAB.
Example 1: How to Permute 3×3 Array Dimension in MATLAB
The following example uses the permute() function to permute 3×3 array dimensions in MATLAB:
B= permute(A,[3 2 1])
The above code uses the permute() function to shuffle the elements of the matrix A according to the order specified by the vector dimorder. The dimorder vector is [3 2 1], which means that the third dimension of the matrix (the columns) is shuffled first, then the second dimension (the rows), and finally the first dimension (the elements). The final output of this code will be:
Example 2: How to Permute 3D Array Dimension in MATLAB
Another example provided below is a 3D array that uses 2 rows, 3 columns, and 2 depths. It uses the rand() function to generate a matrix of numbers and then uses the permute() function to permute the array dimension in MATLAB:
B = permute(A,[2 3 1])
The above code uses the permute() function to shuffle the elements of the array A according to the order specified by the vector dimorder. The dimorder vector is [2 3 1], which means that the second dimension of the array (the columns) is shuffled first, then the third dimension (the depths), and finally the first dimension (the rows). The output at the command window will be:
Conclusion
The permute() function is a powerful tool that can be used for a variety of tasks, such as sorting, cryptography, and finding patterns. If you are working with matrices or arrays in MATLAB, the permute() function is a valuable tool that you should be familiar with. In this article, we have discussed the MATLAB function permute(), which can be used to shuffle the elements of a matrix or array. We have also provided some example code to illustrate the use of the permute() function in MATLAB.