Main Content

mustBeFloat

Validate that value is floating-point array

Since R2020b

    Description

    example

    mustBeFloat(value) throws an error if value is not a floating-point array. The floating-point types are single and double, and subclasses of single and double. This function does not return a value.

    mustBeFloat calls the following function to determine if the input is a floating-point number:

    Class support: All MATLAB® classes

    Examples

    collapse all

    Use the mustBeFloat to ensure that the input to a function is a floating-point value.

    The myCalc function restricts the input to a floating-point array.

    function r = myCalc(a)
        arguments
            a {mustBeFloat}
        end
        r = a .* pi/180;
    end

    Passing an array of int8 values results in an error.

    a = int8([2 4 8 16]);
    r = myCalc(a);
    Error using myCalc
     r = myCalc(a);
                ↑
    Invalid argument at position 1. Value must be a floating-point array.

    Input Arguments

    collapse all

    Value to validate, specified as a floating-point array.

    Data Types: single | double

    Tips

    • mustBeFloat 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