Main Content

mustBeUnderlyingType

Validate that value has specified underlying type

Description

example

mustBeUnderlyingType(,typename)throws an error ifdoes not have underlying data typetypename。这个函数并不return a value.

mustBeUnderlyingTypecalls the following function to determine if the input has the specified underlying type:

Class support: All MATLAB®classes

Examples

collapse all

UsemustBeUnderlyingTypeto validate that the input has underlying typedouble

Create adistributedarray (requires Parallel Computing Toolbox™) and then validate that the underlying data type isdouble

x = distributed(single(1:10)); mustBeUnderlyingType(x,"double")
使用“本地”配置文件启动并行池(Parpool)连接到并行池(工人数:6)。
Value must have underlying type 'double'.

mustBeUnderlyingTypethrows an error because the underlying type of the distributed array issingle

UsemustBeUnderlyingTypeto restrict the input argument values that are accepted by a function. You can accomplish this by adding an争论block to the function that validates the input arguments.

This function declares one input argument. In the争论block, the input is required to have an underlying data type ofsingle

functiony = mbSingle(input)争论input{mustBeUnderlyingType(input,"single")}enddisp("Input is class "+类(输入)+。.." with underlying type "+ underlyingType(input) +".")end

Call the function with adistributedvector (requires Parallel Computing Toolbox) that has underlying data of typesingle。Since the input passes the argument validation, thembSinglefunction prints information about the class and underlying type.

x = distributed(single(1:10)); mbSingle(x)
使用“本地”配置文件启动并行池(Parpool)连接到并行池(工人数:6)。输入是分布底层类型的类。

Input Arguments

collapse all

Value to validate, specified as a scalar, array, or object.

Example:MustbeunderingType(魔术(4),“单身”)

Name of data type to test, specified as a character vector or string scalar.

Example:mustBeUnderlyingType(X,"double")throws an error isXdoes not have underlying typedouble

Data Types:char|string

Tips

  • mustBeUnderlyingTypeis designed to be used for property and function argument validation.

Extended Capabilities

Introduced in R2020b