5.3.2 Converting Numerical Data to Strings

Apart from the string concatenation functions (see Concatenating Strings)
which cast numerical data to the corresponding ASCII characters, there are
several functions that format numerical data as strings. mat2str and
num2str convert real or complex matrices, while int2str converts
integer matrices. int2str takes the real part of complex values and
round fractional values to integer. A more flexible way to format numerical
data as strings is the sprintf function (see Formatted Output,
sprintf).

Function File: s =mat2str(x, n)

Function File: s =mat2str(x, n, "class")

Format real, complex, and logical matrices as strings. The
returned string may be used to reconstruct the original matrix by using
the eval function.

The precision of the values is given by n. If n is a
scalar then both real and imaginary parts of the matrix are printed
to the same precision. Otherwise n(1) defines the
precision of the real part and n(2) defines the
precision of the imaginary part. The default for n is 15.

If the argument "class" is given then the class of x is
included in the string in such a way that eval will result in the
construction of a matrix of the same class.

Convert a number (or array) to a string (or a character array). The
optional second argument may either give the number of significant
digits (precision) to be used in the output or a format
template string (format) as in sprintf (see Formatted Output). num2str can also handle complex numbers.