Main Content

mustBeScalarOrEmpty

Validate that value is scalar or empty

    Description

    example

    mustBeScalarOrEmpty(value)throws an error ifvalue不是一个标量或不是空的。这个函数能源部s not return a value.

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

    Examples

    collapse all

    UsemustBeScalarOrEmptyto restrict the values allowed for a function input argument.

    functionv = buildVector(inc)argumentsinc{mustBeScalarOrEmpty}endv = 1:inc:10;end

    Passing a nonscalar to thebuildVectorfunction 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

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

    Introduced in R2020b