mustBeNonmissing

Validate that value is not missing

    Description

    example

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

    mustBeNonmissing calls the following 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 takes a 1-by-3 string array and uses the elements to label the x- and y-axes 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
    Invalid argument at position 1. Value must not have missing data.

    Input Arguments

    collapse all

    Value to validate, specified as 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.

    Introduced in R2020b