How to use flip() In MATLAB
The flip() function is used to flip the order of the specified string.
Syntax: flip(A)
flip(A, dim)
Here,
flip(A) function is used to return an array of the same size as A, but with the reversed order of the elements.
flip(A, dim) function is used to reverses the order of the elements of A along dimension dim. For example, if A is a matrix, then flip(A,1) reverses the elements in each column, and flip(A,2) reverses the elements in each row.
Example 1:
Matlab
% MATLAB code for reverse % string using flip() % Initializing a string string = 'w3wiki' ; % Calling the flip() function % over the above string to % reverse its characters Reversed_String = flip(string) |
Output:
Example 2:
Matlab
% MATLAB code for reverse % string using flip() % Initializing a string string = [ 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' ]; % Calling the flip() function % over the above string along with % first dimensions to % reverse its elements Reversed_String = flip(string, 1) |
Output:
How to reverse a string in MATLAB?
In this article, we are going to discuss the “Reversing of a string” in MATLAB which can be done in multiple approaches that are illustrated below: