Main Content

mustBeScalarOrEmpty

Validate that value is scalar or empty

    Description

    example

    mustBeScalarOrEmpty(value) throws an error if value is not a scalar or is not empty. This function does not return a value.

    mustBeScalarOrEmpty calls the following function to determine if the input is scalar or empty:

    Examples

    collapse all

    Use mustBeScalarOrEmpty to restrict the values allowed for a function input argument.

    function v = buildVector(inc)
        arguments
            inc {mustBeScalarOrEmpty}
        end
        v = 1:inc:10;
    end

    Passing a nonscalar to the buildVector function results in an error.

    v = buildVector([1 2]);
    Error using buildVector
    Invalid argument at position 1. Value must be scalar.

    Input Arguments

    collapse all

    Value to validate, specified as a scalar or an empty value. Values that are not a scalar or are not empty result in an error.

    Example: []

    Tips

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

    Introduced in R2020b