matlab.unittest.constraints.IsReal 类
命名空间: matlab.unittest.constraints
超类: matlab.unittest.constraints.BooleanConstraint
测试数组元素是否为实数值
描述
matlab.unittest.constraints.IsReal
类提供一个约束来测试数组的元素是否为实数值。
创建对象
描述
c = matlab.unittest.constraints.IsReal
创建一个约束来测试数组的所有元素是否均为实数值。不使用复数存储的数值数组满足该约束。
示例
测试数组元素是否为实数值
使用 IsReal
约束测试数值数组。
首先,导入此示例中使用的类。
import matlab.unittest.TestCase import matlab.unittest.constraints.IsReal
创建一个供交互测试的测试用例。
testCase = TestCase.forInteractiveUse;
验证值 5
是否为实数。
testCase.verifyThat(5,IsReal)
Verification passed.
立即测试值 complex(5)
。尽管虚部的值为零,测试仍失败,因为该值存储为复数。
testCase.verifyThat(complex(5),IsReal)
Verification failed. --------------------- Framework Diagnostic: --------------------- IsReal failed. --> The value must be real. Actual Value: 5.000000000000000 + 0.000000000000000i
测试值 sqrt(-1)
。测试失败。
testCase.verifyThat(sqrt(-1),IsReal)
Verification failed. --------------------- Framework Diagnostic: --------------------- IsReal failed. --> The value must be real. Actual Value: 0.000000000000000 + 1.000000000000000i
测试向量 [1 1 2 3 5 8 13]
是否满足 IsReal
约束。测试通过,因为所有向量元素均为实数。
testCase.verifyThat([1 1 2 3 5 8 13],IsReal)
Verification passed.
测试包含无限值和 NaN
值的向量。测试通过。
testCase.verifyThat([-Inf 5 NaN],IsReal)
Verification passed.
验证矩阵 [1 NaN; -Inf 3i]
不是实矩阵。
testCase.verifyThat([1 NaN; -Inf 3i],~IsReal)
Verification passed.
版本历史记录
在 R2013a 中推出
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)