How to inverse a vector in MATLAB?
Last Updated :
27 Jan, 2022
In this article, we are going to discuss the “Inversion of a vector” in MATLAB which can be done in three different approaches that are illustrated below:
Method 1: By using flipud() function
The flipud() function is used for flipping the specified vector’s elements.
Syntax:
flipud(A)
Here, flipud(A) function is used to return a vector with reversed elements of the same length of the specified vector “A”.
Example 1:
Matlab
v = [10;9;8;7;6;5]
flipud(v)
|
Output:
Example 2:
Matlab
A = { 'a' 'b' ; 'c' 'd' }
flipud(A)
|
Output:
Method 2: By using fliplr() function
The fliplr() function is used for flipping the specified row vector’s elements.
Syntax:’
fliplr(A)
Here, fliplr(A) function is used to return a vector with reversed elements of the same length of the specified row vector “A”.
Example 1:
Output:
Example 2:
Matlab
A = { 'a' 'b' ; 'c' 'd' }
fliplr(A)
|
Output:
Method 3: By using “vector(end:-1:1)” operation
The end keyword in MATLAB is used for either finding a row or column index to reference the last element,
Example 1:
Matlab
v = [10;9;8;7;6;5]
v( end :-1:1)
|
Output:
Example 2:
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...