MATLAB Function Reference
num2str

Number to string conversion

Syntax

• ```str` `=` `num2str(A)
str` `=` `num2str(A,`precision````)
```str = num2str(A,`format`)
```

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,precision) ``` converts the array `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,format) ``` converts array `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(pi)` is `3.142.`

`num2str(eps)` is `2.22e-16`.

`num2str(magic(2))` produces the string matrix

• ```1  3
4  2
```

`fprintf`, `int2str`, `sprintf`