Main Content


Validate that value is scalar or empty

Since R2020b



    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:


    collapse all

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

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

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

    v = buildVector([1 2]);
    Error using buildVector
     v = buildVector([1 2]);
    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: []


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