Main Content


Validate that value has specified underlying type

Since R2020b



mustBeUnderlyingType(value,typenames) throws an error if value does not have any of the underlying data types specified by typenames. This function does not return a value.

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

Class support: All MATLAB® classes


collapse all

Use mustBeUnderlyingType to validate that the input has underlying type double.

Create a distributed array (requires Parallel Computing Toolbox™) and then validate that the underlying data type is double.

x = distributed(single(1:10));
Starting parallel pool (parpool) using the 'local' profile ...
Connected to the parallel pool (number of workers: 6).
Value must have underlying type 'double'.

mustBeUnderlyingType throws an error because the underlying type of the distributed array is single.

You can specify more than one data type to check against. (since R2024a) Define a second distributed array of type double.

y = distributed(double(1:10));

mustBeUnderlyingType does not throw an error for x or y when both double and single are specified.


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

This function declares one input argument. In the arguments block, the input is required to have an underlying data type of single.

function y = mbSingle(input)
        input {mustBeUnderlyingType(input,"single")}

    disp("Input is class " + class(input) + ...
        " with underlying type " + underlyingType(input) + ".")

Call the function with a distributed vector (requires Parallel Computing Toolbox) that has underlying data of type single. Since the input passes the argument validation, the mbSingle function prints information about the class and underlying type.

x = distributed(single(1:10));
Starting parallel pool (parpool) using the 'local' profile ...
Connected to the parallel pool (number of workers: 6).
Input is class distributed with underlying type single.

Input Arguments

collapse all

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

Example: mustBeUnderlyingType(magic(4),"single")

Name of one or more data types to test, specified as a string array, character vector, or cell array of character vectors.

Example: mustBeUnderlyingType(X,["double","single"]) throws an error is X does not have underlying type double or single.

Data Types: char | string


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

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2020b

expand all