MATLAB Function Reference Previous page   Next Page
mat2str

Convert matrix to string

Syntax

Description

str = mat2str(A) converts matrix A into a string, suitable for input to the eval function, using full precision.

str = mat2str(A,n) converts matrix A using n digits of precision.

str = mat2str(A, 'class') creates a string with the name of the class of A included. This option ensures that the result of evaluating str will also contain the class information.

str = mat2str(A, n, 'class') uses n digits of precision and includes the class information.

Limitations

The mat2str function is intended to operate on scalar, vector, or rectangular array inputs only. An error will result if A is a multidimensional array.

Examples

Example 1

Consider the matrix

The statement

produces

where A is a string of 21 characters, including the square brackets, spaces, and a semicolon.

eval(mat2str(x)) reproduces x.

Example 2

Create a 1-by-6 matrix of signed 16-bit integers, and then use mat2str to convert the matrix to a 1-by-33 character array, A. Note that output string A includes the class name, int16:

Evaluating the string A gives you an output x2 that is the same as the original int16 matrix:

See Also

num2str, int2str, str2num, sprintf, fprintf


Previous page  mat2cell material Next page

© 1994-2005 The MathWorks, Inc.