Main Content

str2double, double

将 Stateflow 图中的字符串转换为双精度值

描述

示例

X = str2double(str) 将字符串 str 中的文本转换为双精度值。

  • 在使用 MATLAB® 作为动作语言的图中,str2double 返回复数值。

  • 在使用 C 语言作为动作语言的图中,str2double 返回实数值。

如果 str2double 无法将文本转换为数字,它将返回 NaN 值。

示例

X = double(str) 是在使用 MATLAB 作为动作语言的图中执行 str2double(str) 的另一种方式。

注意

使用 C 语言作为动作语言的 Stateflow® 图仅支持使用数值参量调用 double

示例

全部展开

将字符串 "-12.345" 转换为双精度数值。

str = "-12.345";
X = str2double(str);

Stateflow chart that uses the str2double operator in a state.

或者,在使用 MATLAB 作为动作语言的图中,您可以使用运算符 double

str = "-12.345";
X = double(str);

Stateflow chart that uses the contains operator in a state.

返回值 123400

str = "1.234e5";
X = str2double(str);

Stateflow chart that uses the str2double operator in a state.

或者,在使用 MATLAB 作为动作语言的图中,您可以使用运算符 double

str = "1.234e5";
X = str2double(str);

Stateflow chart that uses the contains operator in a state.

输入参数

全部展开

输入值,指定为字符串标量。

str 必须包含表示数字的文本,包括:

  • 数字

  • 小数点

  • 前导 +- 符号

  • e,后接 10 的幂指数

  • 后跟 ij 的虚部(在使用 C 语言作为动作语言的图中不受支持)

在使用 MATLAB 作为动作语言的图中,需要用双引号将文字字符串引起来。

限制

版本历史记录

在 R2018b 中推出