Main Content

anymissing

Determine if any array element is missing

Description

example

TF = anymissing(A) returns logical 1 (true) if at least one element of A is missing. It returns 0 (false) if no element is missing.

Missing values are defined according to the data type of A:

  • NaNdouble, single, duration, and calendarDuration

  • NaTdatetime

  • <missing>string

  • <undefined>categorical

  • ' 'char

  • {''}cell of character vectors

For data types with no default definition of a standard missing value, anymissing returns logical 0 (false).

Examples

collapse all

Create a row vector A of type double. Determine if at least one element of A is missing, that is, if A contains at least one NaN value.

A = [3.14 NaN -2.718 1.414 0.5];
TF = anymissing(A)
TF = logical
   1

Create a table with variables of different data types.

singleVar = single([1;3;5;7;9;11;13]);
cellstrVar = {'one';'three';'';'seven';'nine';'eleven';'thirteen'};
categoryVar = categorical({'red';'yellow';'blue';'violet';'';'ultraviolet';'orange'});
dateVar = [datetime(2015,1:7,15)]';
stringVar = ["a";"b";"c";"d";"e";"f";"g"];

A = table(singleVar,cellstrVar,categoryVar,dateVar,stringVar)
A=7×5 table
    singleVar     cellstrVar     categoryVar      dateVar      stringVar
    _________    ____________    ___________    ___________    _________

        1        {'one'     }    red            15-Jan-2015       "a"   
        3        {'three'   }    yellow         15-Feb-2015       "b"   
        5        {0x0 char  }    blue           15-Mar-2015       "c"   
        7        {'seven'   }    violet         15-Apr-2015       "d"   
        9        {'nine'    }    <undefined>    15-May-2015       "e"   
       11        {'eleven'  }    ultraviolet    15-Jun-2015       "f"   
       13        {'thirteen'}    orange         15-Jul-2015       "g"   

Determine if any element of the table has a missing value.

anymissing returns logical 1 because at least one element of A is missing. Here, the third element of cellstrVar is '' and the fifth element of categoryVar is <undefined>, which are missing values.

TF = anymissing(A)
TF = logical
   1

Create a 3-D array and determine if at least one of its elements is missing.

A(:,:,1) = [2 1; 3 5];
A(:,:,2) = [NaN 0; 0 NaN];
A(:,:,3) = [-2 9; 4 1]
A = 
A(:,:,1) =

     2     1
     3     5


A(:,:,2) =

   NaN     0
     0   NaN


A(:,:,3) =

    -2     9
     4     1

TF = anymissing(A)
TF = logical
   1

Input Arguments

collapse all

Input data, specified as a scalar, vector, matrix, multidimensional array, cell array of character vectors, table, or timetable.

  • If A is a timetable, then anymissing operates on the table data only and ignores NaT or NaN values in the row times.

  • If A is a cell array, then anymissing only detects missing elements when A is a cell array of character vectors.

Example: ["a" "b" missing "d"]

Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | cell | table | timetable | categorical | datetime | duration | calendarDuration
Complex Number Support: Yes

Version History

Introduced in R2022a