num2str

Returns a string or a string array after converting the input x. Input x can be a scalar, complex number, or matrix. An optional argument, precision, can be used to format the output, R, by specifying the number of significant digits. Valid values of R are positive integers.

Syntax

R = num2str(x)

R = num2str(x, precision)

Inputs

x
Type: scalar | complex number | matrix
precision (optional)
Specify the format of the output R.
Type: Finite, positive integer

Outputs

R
Type: string | mat

Examples

Scalar to string example:
R = num2str(2.345e+5)
R = 234500
Scalar to string example with precision:
R = num2str(0.64247255268, 6)
R = 0.642473
Complex to string example:
R = num2str(24 + 7i)
R = 24+7i
Matrix to string example:
R = num2str([123, 456, 789; 45.56, 78.98, 45.94])
R =
123    456    789
45.56  78.98  45.94