Matlab

How to Flip Array Left to Right in MATLAB

An array is a crucial building block of MATLAB programming that can store a collection of data elements of the same type. They are mostly used to represent data in a way that makes it easy to manipulate and analyze. Flipping an array is one of the most common operations on arrays, which is a process of reversing the order of the elements in an array. Flipping an array can be useful for a variety of purposes, such as data visualization and analysis, using the data function that only works with row vectors, and so on.

Read this if you want to flip the array left to right in MATLAB.

How to Flip an Array Left to Right in MATLAB

MATLAB includes a built-in function named fliplr() that is designed solely to flip the array elements from left to right. This function is one of the most straightforward functions that takes only a single argument as an input (array) and returns a flipped version of your desired array in MATLAB.

Syntax

The fliplr() function uses the following syntax in MATLAB:

Here, A is desired array argument passed through fliplr() function and is going to be flipped in the left-right direction.

Examples

You can follow the below-given example to understand the working of fliplr() function in MATLAB.

Example 1: Flip 3×3 Array Left to Right in MATLAB Using fliplr() Function

The following example uses the rand(3) function to generate a 3×3 matrix and then uses the fliplr() function to flip the elements of the array from the left-right direction.

A=rand(3)

B=fliplr(A)

Example 2: Flip 6×6 Array Left to Right in MATLAB Using fliplr() Function

The following example uses the magic(6) function to generate a 6×6 matrix and then uses the fliplr() function to flip the array elements from the left-right direction.

A=magic(6)

B=fliplr(A)

Conclusion

Flipping the array from left to right in MATLAB is a crucial task that is beneficial for data visualizing and analyzing. The fliplr() is a built-in MATLAB function that is used to quickly flip your array elements from the left-right direction. You only have to pass an array as an argument and it will flip the desired array. This guide has demonstrated the basic process of using the fliplr() function in MATLAB to flip an array from left to right. The examples are provided for beginners’ help as well as to clearly understand the working of the fliplr() function in MATLAB.

About the author

Awais Khan

I'm an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.