How to use sprintf() In MATLAB

The sprintf() function is used to write formatted data to a string.

Syntax:

sprintf(format, A)

Here, sprintf(format, A) is used to format the data in A over the specified format string.

Example:

Matlab




% MATLAB code for removal of 
% decimal points using sprintf()
% Initializing some values
A = 3.000;
B = 1.420;
C = 0.023;
  
% Calling the sprintf() function over
% the above values
sprintf('%.f', A)
sprintf('%.f', B)
sprintf('%.f', C)


Output:

ans = 3
ans = 1
ans = 0

How to remove decimal in MATLAB?

In this article, we are going to discuss the “Removal of decimal point” in MATLAB which can be done using sprintf(), fix(), floor(), round() and num2str() functions which are illustrated below.

Similar Reads

Using sprintf()

The sprintf() function is used to write formatted data to a string....

Using fix()

...

Using floor()

The fix() function is used to round the specified values towards zero....

Using round()

...

Using num2str( )

The floor() function is used to round the specified values towards minus infinity....

Contact Us