MATLAB 帮助中心
验证值小于等于另一个值
mustBeLessThanOrEqual(value,c)
如果 value 中有任何元素大于标量 c,mustBeLessThanOrEqual(value,c) 将抛出错误。此函数不返回值。
value
c
mustBeLessThanOrEqual 调用以下函数来确定 value 是否小于或等于 c:
mustBeLessThanOrEqual
le
isreal
isnumeric
islogical
支持的类:重载 mustBeLessThanOrEqual 调用的函数的所有数值类、logical 和 MATLAB® 类。
logical
此函数忽略第一个输入参量中的空值。因此,当属性或函数参量值为空时,不会抛出错误。
示例
全部折叠
使用 mustBeLessThanOrEqual 验证第一个输入中的值小于等于第二个输入中的值。
mustBeLessThanOrEqual([3 4 5],2)
Value must be less than or equal to 2.
将属性值限制为小于等于指定的值。
该类将 Prop1 的值限制为小于等于 2。
Prop1
2
classdef MyClass properties Prop1 {mustBeLessThanOrEqual(Prop1,2)} end end
创建一个对象,并向其属性赋值。
obj = MyClass; obj.Prop1 = 3;
Error setting property 'Prop1' of class 'MyClass'. Value must be less than or equal to 2.
当您向属性赋值时,MATLAB 会使用赋给属性的值调用 mustBeLessThanOrEqual。mustBeLessThanOrEqual 将引发错误,因为值 3 不小于等于 2。
3
此函数将输入参量限制为小于或等于 5 的值。
function r = mbLessThanOrEqual(x) arguments x {mustBeLessThanOrEqual(x,5)} end r = x + 5; end
使用包含大于 5 的值的向量调用该函数不满足 mustBeLessThanOrEqual 定义的要求,并会引发错误。
x = [1.27, 4.54, 3.9, 5.1, .531]; r = mbLessThanOrEqual(x);
Error using mbLessThanOrEqual (line 3) r = mbLessThanOrEqual(x); ^ Invalid argument at position 1. Value must be less than or equal to 5.
要验证的值,指定为标量或由以下任一类型的值组成的数组:
logical、char 或数值类
char
实现 le、isscalar、isreal 以及 isnumeric 或 islogical 的 MATLAB 类
isscalar
常量值,value 参量必须小于或等于该值,指定为以下标量之一:
logical、char、string 和数值类
string
mustBeLessThanOrEqual 用于属性和函数参量验证。
全部展开
mustBeLessThanOrEqual 函数完全支持 GPU 数组。要在 GPU 上运行该函数,请将输入数据指定为 gpuArray (Parallel Computing Toolbox)。有关详细信息,请参阅在 GPU 上运行 MATLAB 函数 (Parallel Computing Toolbox)。
gpuArray
此函数完全支持分布式数组。有关详细信息,请参阅使用分布式数组运行 MATLAB 函数 (Parallel Computing Toolbox)。
在 R2017a 中推出
arguments | mustBeNumericOrLogical | mustBeReal | mustBeLessThan | mustBeGreaterThanOrEqual
arguments
mustBeNumericOrLogical
mustBeReal
mustBeLessThan
mustBeGreaterThanOrEqual
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 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
欧洲
亚太
联系您当地的办事处