num2str
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.
Syntax
R = num2str(x)
R = num2str(x, precision)
R = num2str(x, format)
Inputs
- x
- Type: scalar | complex number | matrix
- format
- 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.
- precision (optional)
- Optional argument specifying the precision in R.
Outputs
- R
- Type: string | mat
Examples:
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