MATLAB 帮助中心
验证值是有限值
mustBeFinite(value)
如果 value 不是有限值,mustBeFinite(value) 将抛出错误。不为 NaN 或 Inf 的数值即为有限值。此函数不返回值。
value
NaN
Inf
mustBeFinite 调用 allfinite 函数来确定输入是否为有限值。
mustBeFinite
allfinite
支持的类:重载 isfinite 或 allfinite 的所有数值类、logical、char 和 MATLAB® 类。
isfinite
logical
char
此函数忽略输入参量中的空值。因此,当属性或函数参量值为空时,不会抛出错误。
示例
全部折叠
使用 mustBeFinite 验证任何数组元素均不为 NaN 或 Inf。
d = 0:9; A = 1./d; mustBeFinite(A)
Value must be finite.
被 d 除使得一个元素变成 Inf,因而引发了错误。
d
该类将 Prop1 的值限制为有限值。
Prop1
classdef MyClass properties Prop1 {mustBeFinite} end end
创建一个对象,并向其属性赋值。
d = 0:9; obj = MyClass; obj.Prop1 = 1./d;
Error setting property 'Prop1' of class 'MyClass'. Value must be finite.
当您向属性赋值时,MATLAB 会使用赋给属性的值调用 mustBeFinite。mustBeFinite 将引发错误,因为值被 0 除的结果是 Inf。
0
此函数声明一个输入参量,该参量必须为不包含 Inf 或 NaN 元素的双精度向量。
function s = mbFinite(x) arguments x (1,:) double {mustBeFinite} end n = length(x); m = sum(x)/n; s = sqrt(sum((x-m).^2/n)); end
使用不满足 mustBeFinite 要求的输入调用该函数会引发错误。
values = [12.7, 45.4, 98.9, Inf, 53.1]; s = mbFinite(values);
Error using mbFinite (line 3) s = mbFinite(values); ^^^^^^ Invalid argument at position 1. Value must be finite.
要验证的值,指定为标量或由以下任一类型的值组成的数组:
所有 MATLAB 数值类、logical 或 char
所有重载 allfinite 或 isfinite 的 MATLAB 类
数据类型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char 复数支持: 是
single
double
int8
int16
int32
int64
uint8
uint16
uint32
uint64
mustBeFinite 用于属性和函数参量验证。
全部展开
此函数完全支持分布式数组。有关详细信息,请参阅使用分布式数组运行 MATLAB 函数 (Parallel Computing Toolbox)。
mustBeFinite 调用 allfinite 函数来确定输入是否为有限值。以前,它调用 isfinite 函数。此更改不影响 mustBeFinite 的行为。
arguments | allfinite | isfinite | mustBeReal | mustBeNonNan | mustBeNonmissing
arguments
mustBeReal
mustBeNonNan
mustBeNonmissing
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
欧洲
亚太
联系您当地的办事处