| MATLAB Function Reference | ![]() |
Syntax
Description
The num2str function converts numbers to their string representations. This function is useful for labeling and titling plots with numeric values.
str = num2str(a)
converts array A into a string representation str with roughly four digits of precision and an exponent if required.
str = num2str(a, converts the array precision)
A into a string representation str with maximum precision specified by precision. Argument precision specifies the number of digits the output string is to contain. The default is four.
str = num2str(A, converts array format)
A using the supplied format. By default, this is '%11.4g', which signifies four significant digits in exponential or fixed-point notation, whichever is shorter. (See fprintf for format string details.)
Examples
num2str with a format of %10.5e\n returns a matrix of strings in exponential format, having 5 decimal places, with each element separated by a newline character:
x = rand(3) * 9999; % Create a 2-by-3 matrix. x(3,:) = []; A = num2str(x, '%10.5e\n') % Convert to string array. A = 6.87255e+003 1.55597e+003 8.55890e+003 3.46077e+003 1.91097e+003 4.90201e+003
See Also
mat2str, int2str, str2num, sprintf, fprintf
| num2hex | numel | ![]() |
© 1994-2005 The MathWorks, Inc.