| Contents | Index |
str = num2str(A)
str = num2str(A,precision)
str = num2str(A,formatSpec)
str = num2str(A) converts array A into a string representation str. When A contains floating-point numbers, the output format depends upon the size of the original values and sometimes includes exponents.
str = num2str(A,precision) converts the array A with the maximum number of digits specified by precision.
str = num2str(A,formatSpec) converts array A using the supplied formatSpec, as described on the fprintf function reference page.
num2str is useful for labeling and titling plots with numeric values.
Unlike fprintf, the num2str function trims any leading spaces from a string, even when used with the space character flag. For example, num2str(42.67,'% 10.2f') returns a 1-by-5 character array '42.67'.
Convert pi and eps to text strings.
str = num2str(pi)
str = 3.1416
str = num2str(eps)
str = 2.2204e-16
Specify the number of significant digits for floating-point values.
If you run this example, your values of A might differ.
A = randn(2,2); precision = 3; str = num2str(A,precision)
str = 0.538 -2.26 1.83 0.862
Specify the width, precision, and other formatting for an array of floating-point values.
If you run this example, your values of A might differ.
A = rand(2,3) * 9999;
formatSpec = '%10.5e\n';
str = num2str(A,formatSpec)str = 6.87255e+03 1.55597e+03 8.55890e+03 3.46077e+03 1.91097e+03 4.90201e+03
The format '%10.5e' prints each value in exponential format with five decimal places, and '\n' prints a new line character.
cast | fprintf | int2str | mat2str | sprintf | str2num
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |