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


R = num2str(x)

R = num2str(x, precision)

R = num2str(x, format)


Type: scalar | complex number | matrix
Optional argument specifying the format in R. format must be a valid numeric type format such as the format used in the printf command for numerical values.
Type: string
precision (optional)
Optional argument specifying the precision in R.
Type: Finite, positive integer


Type: string | mat


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