mat2str - Convert matrix to characters - MATLAB (original) (raw)

Main Content

Convert matrix to characters

Syntax

Description

chr = mat2str([X](#d126e1037287)) converts the numeric or logical matrix X into a character vector that represents the matrix, with up to 15 digits of precision.

You can use chr as input to the eval function. For example, A = eval(chr) reproduces the values from the original matrix to the precision specified in chr.

example

chr = mat2str([X](#d126e1037287),[n](#d126e1037306)) converts X using n digits of precision.

example

chr = mat2str(___,'class') includes the name of the class, or data type, of X in chr. You can use this syntax with any of the arguments from the previous syntaxes.

If you use this syntax to produce chr, then A = eval(chr) also reproduces the data type of the original matrix.

example

Examples

collapse all

Convert a numeric matrix to a character vector.

chr = mat2str([3.85 2.91; 7.74 8.99])

chr = '[3.85 2.91;7.74 8.99]'

You can convert chr back to a numeric matrix using the eval function.

A = 2×2

3.8500    2.9100
7.7400    8.9900

Convert a numeric matrix to a character vector, to three digits of precision.

chr = mat2str([3.1416 2.7183],3)

Create an array of integers and convert it to a character vector. By default, the output of mat2str represents an array of doubles. To represent a different numeric type in the output, use the 'class' input argument.

Create a vector of 16-bit unsigned integers.

X = 1×2 uint16 row vector

256 512

Convert X to a character vector, including the data type of X.

chr = 'uint16([256 512])'

Convert chr back to an array of integers. A has the same values and data type as X.

A = 1×2 uint16 row vector

256 512

Input Arguments

collapse all

Input array, specified as a numeric or logical matrix.

Digits of precision, specified as a positive integer.

Tips

Extended Capabilities

expand all

Usage notes and limitations:

The mat2str function supports GPU array input with these usage notes and limitations:

This function accepts GPU arrays, but does not run on a GPU.

For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

Version History

Introduced before R2006a

expand all

You can generate C/C++ code for the mat2str function.