| by Arround The Web | No comments

How to Inverse a Vector in MATLAB?

In MATLAB, a vector is like a list of numbers arranged in a straight line. An inverse vector is a vector that, when multiplied by the original vector, produces the identity vector.

To invert a vector in MATLAB, there are several methods available. The first method involves using the flipud() function, which flips the vector vertically. The second method uses the fliplr() function to horizontally flip the vector. Lastly, the third method involves using the operation vector(end:-1:1), which reverses vector elements order.

These methods provide different ways to achieve the inversion of a vector in MATLAB, offering flexibility and convenience for manipulating data.

Now we will explore each of these methods in detail, along with their corresponding example code.

Method 1: By Using the flipud() Function

The flipud() function is used to flip the input vector vertically while inverting its order. A new vector will be output containing all entities of the original vector but in reverse order.

Syntax

 

inverted_vector = flipud(vector)

 

Example

 

vector = [1; 2; 3; 4; 5];
inverted_vector = flipud(vector);
disp(inverted_vector);

 

Method 2: By Using the fliplr() Function

The fliplr() function is used to flip the input vector horizontally, thereby inverting the order of its elements. A new vector will be the output containing all original elements of the input vector, but their order is reversed.

Syntax

 

inverted_vector = fliplr(vector)

 

Example

 

vector = [1, 2, 3, 4, 5];
inverted_vector = fliplr(vector);
disp(inverted_vector);

 

Method 3: By Using the “vector(end:-1:1)” Operation

This method directly accesses the elements of a defined vector in the opposite order by using indexing. The expression end:-1:1 represents a range that starts from the last element of the vector (end) and decrements by 1 until the first element (1) is reached.

Syntax

 

inverted_vector = vector(end:-1:1)

 

Example

 

vector = [1, 2, 3, 4, 5];
inverted_vector = vector(end:-1:1);
disp(inverted_vector)

 

Conclusion

This article explains three methods to invert a vector in MATLAB: using the flipud() function, the fliplr() function, or the indexing operation vector(end:-1:1). These three methods achieve the same result of inverting the order of a vector in MATLAB, but they differ in terms of the functions used or the indexing approach employed. Each of these three methods are covered here. Read the article.

Share Button

Source: linuxhint.com

Leave a Reply