Main Content

mustBeNonmissing

Validate that input does not contain missing values

Since R2020b

    Description

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

    mustBeNonmissing calls the anymissing function to determine if the input contains missing values.

    Class support: single, double, string, cell of character vectors, categorical, datetime, duration, calendarDuration, table, timetable, and MATLAB® classes that overload anymissing or ismissing.

    example

    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 (line 3)
     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 one of these types or as a cell array of character vectors:

    • single, double, string, char, categorical, datetime, duration, calendarDuration, table, or timetable

    • All MATLAB classes that overload anymissing or ismissing

    Data Types: single | double | string | char | cell | categorical | datetime | duration | calendarDuration | table | timetable

    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 anymissing function.

    Extended Capabilities

    expand all

    Version History

    Introduced in R2020b

    expand all