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.