mustBeLessThanOrEqual
验证值小于等于另一个值
说明
示例
验证第一个输入小于等于第二个输入
使用 mustBeLessThanOrEqual
验证第一个输入中的值小于等于第二个输入中的值。
mustBeLessThanOrEqual([3 4 5],2)
Values must be less than or equal to 2.
限制属性值
将属性值限制为小于等于指定的值。
该类将 Prop1
的值限制为小于等于 2
。
classdef MyClass properties Prop1 {mustBeLessThanOrEqual(Prop1,2)} end end
创建一个对象,并向其属性赋值。
obj = MyClass; obj.Prop1 = 3;
Error setting 'Prop1' property of 'MyClass' class. Values must be less than or equal to 2.
当您向属性赋值时,MATLAB 会使用赋给属性的值调用 mustBeLessThanOrEqual
。mustBeLessThanOrEqual
将引发错误,因为值 3
不小于等于 2
。
限制函数参数值
此函数将输入参数限制为小于或等于 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 r = mbLessThanOrEqual(x); ↑ Invalid input argument at position 1. Value must be less than or equal to 5.
输入参数
提示
mustBeLessThanOrEqual
用于属性和函数参数验证。
扩展功能
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
GPU 数组
通过使用 Parallel Computing Toolbox™ 在图形处理单元 (GPU) 上运行来加快代码执行。
此函数完全支持 GPU 数组。有关详细信息,请参阅Run MATLAB Functions on a GPU (Parallel Computing Toolbox)。
分布式数组
使用 Parallel Computing Toolbox™ 在集群的组合内存中对大型数组进行分区。
此函数完全支持分布式数组。有关详细信息,请参阅Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox)。
版本历史记录
在 R2017a 中推出
MATLAB 命令
您点击的链接对应于以下 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:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)