MATLAB Function Reference |
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, '
creates a string with the name of the class of class
')
A
included. This option ensures that the result of evaluating str
will also contain the class information.
str = mat2str(A, n, '
uses class
')
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.
Example 1
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
:
x1 = int16([-300 407 213 418 32 -125]); A = mat2str(x1, 'class') A = int16([-300 407 213 418 32 -125]) class(A) ans = char
Evaluating the string A
gives you an output x2
that is the same as the original int16
matrix:
x2 = eval(A); if isnumeric(x2) && isa(x2, 'int16') && all(x2 == x1) disp 'Conversion back to int16 worked' end Conversion back to int16 worked
See Also
num2str
, int2str
, str2num
, sprintf
, fprintf
mat2cell | material |
© 1994-2005 The MathWorks, Inc.