How to use flip( ) and  sprintf() In MATLAB

The sprintf() function is used to format the data into a string or character vector.

Syntax:  sprintf(formatSpec, A1, …, An)

Here,   sprintf(formatSpec, A1, …, An) is used to format the data in arrays A1,…, An uses the formatting operators specified by formatSpec and returns the resulting text in str.

 

Example:

Matlab




% MATLAB code for reverse a number
% using flip() and sprintf()
% Calling the flip() function over the
% sprintf() function with number
% 5678 as its parameter to reverse
Reversed_Number = flip(sprintf('%d', 5678), 2)


 
 

Output:

Reversed_Number = 8765

 



How to reverse a number in MATLAB?

In this article, we will discuss the “Reversing of a number” in MATLAB that can be done using the multiple methods which are illustrated below.

Similar Reads

Using str2num()

The str2num() function is used to convert the specified character array or string to a numeric array....

Using fliplr()

...

Using str2num(), fliplr(), and num2str()

The fliplr() function is used to flip the specified number from left to right....

Using polyval( ) and num2str( )

...

Using flip( ) and  sprintf()

The num2str() function is used to convert the specified numbers to a character array....