Main Content

mustBeNonmissing

Validate that value is not missing

Since R2020b

    Description

    example

    mustBeNonmissing(value) throws an error if value contains missing values. This function does not return a value.

    mustBeNonmissing calls the ismissing function to determine if the input is not missing.

    Class support: All numeric classes, string, and MATLAB® classes that overload ismissing.

    Examples

    collapse all

    The labelPlot function uses the elements of a 1-by-3 string array to label the x- and y-axes of a plot and add a title. The function does not allow missing array elements.

    function labelPlot(labels)
        arguments
            labels (1,3) string  {mustBeNonmissing}
        end
        xlabel(labels(1))
        ylabel(labels(2))
        title(labels(3))
    end

    Create a plot and use the labelPlot function to add labels and a title. The function input array contains a missing element so the mustBeNonmissing function throws an error.

    plot(1:10)
    strLabels = ["X Label",string(missing),"My Plot"];
    labelPlot(strLabels)
    Error using labelPlot
     labelPlot(strLabels)
               ↑
    Invalid argument at position 1. Value must not have missing data.

    Input Arguments

    collapse all

    Value to validate, specified as a scalar or an array of any MATLAB type or user-defined object that supports the ismissing function.

    Tips

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

    • For information on what constitutes a missing value for different types of values, see the ismissing function.

    Extended Capabilities

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

    Version History

    Introduced in R2020b

    expand all