帮助中心帮助中心
将矩阵转换为字符
chr = mat2str(X)
chr = mat2str(X,n)
chr = mat2str(___,'class')
示例
chr = mat2str(X) 将数值矩阵 X 转换为表示矩阵的字符向量,精度最多 15 位。
X
您可以使用 chr 作为 eval 函数的输入。例如,A = eval(chr) 按 chr 中指定的精度重新生成原始矩阵中的值。
chr
eval
A = eval(chr)
chr = mat2str(X,n) 使用 n 位精度转换 X。
n
chr = mat2str(___,'class') 在 chr 中包含 X 的类名或数据类型。您可将此语法与上述语法中的任何参量一起使用。
如果使用此语法生成 chr,则 A = eval(chr) 也会重新生成原始矩阵的数据类型。
全部折叠
将数值矩阵转换为字符向量。
chr = mat2str([3.85 2.91; 7.74 8.99])
chr = '[3.85 2.91;7.74 8.99]'
您可以使用 eval 函数将 chr 转换回数值矩阵。
A = 2×2 3.8500 2.9100 7.7400 8.9900
将数值矩阵转换为字符向量,精度为三位。
chr = mat2str([3.1416 2.7183],3)
chr = '[3.14 2.72]'
创建一个整数数组,然后将其转换为字符向量。默认情况下,mat2str 的输出表示双精度数组。要在输出中表示不同的数值类型,请使用 'class' 输入参量。
mat2str
'class'
创建一个由 16 位无符号整数组成的向量。
X = uint16([256 512])
X = 1x2 uint16 row vector 256 512
将 X 转换为字符向量,包括 X 的数据类型。
chr = mat2str(X,'class')
chr = 'uint16([256 512])'
将 chr 转换回整数数组。A 的值和数据类型与 X 相同。
A
A = 1x2 uint16 row vector 256 512
输入数组,指定为数值矩阵。
精度位数,指定为正整数。
mat2str 仅返回字符数组。从 R2016b 开始,您可以使用 string 函数将数值数组转换为字符串数组。
string
backgroundPool
ThreadPool
此函数完全支持基于线程的环境。有关详细信息,请参阅在基于线程的环境中运行 MATLAB 函数。
用法说明和限制:
此函数接受 GPU 数组,但不在 GPU 上运行。
有关详细信息,请参阅Run MATLAB Functions on a GPU (Parallel Computing Toolbox)。
在 R2006a 之前推出
cast | int2str | num2str | sprintf | str2num | str2double | string
cast
int2str
num2str
sprintf
str2num
str2double
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office