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

  • {''}cell of character vectors

If A is a table, then the data type of each column defines the missing value for that column.

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.

dblVar = [1; 2; 3; 4; 5; 6];
singleVar = single([1; 2; 3; 4; 5; 6]);
cellstrVar = {'one'; 'two'; ''; 'four'; 'five'; 'six'};
categoryVar = categorical({'red'; 'orange'; 'yellow'; ''; 'blue'; 'indigo'});
dateVar = [datetime(2015,1:6,15)]';
stringVar = ["a"; "b"; "c"; "d"; "e"; "f"];

A = table(dblVar,singleVar,cellstrVar,categoryVar,dateVar,stringVar)
A=6×6 table
    dblVar    singleVar    cellstrVar    categoryVar      dateVar      stringVar
    ______    _________    __________    ___________    ___________    _________

      1           1        {'one'   }    red            15-Jan-2015       "a"   
      2           2        {'two'   }    orange         15-Feb-2015       "b"   
      3           3        {0x0 char}    yellow         15-Mar-2015       "c"   
      4           4        {'four'  }    <undefined>    15-Apr-2015       "d"   
      5           5        {'five'  }    blue           15-May-2015       "e"   
      6           6        {'six'   }    indigo         15-Jun-2015       "f"   

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 fourth 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

Tips

  • For input data that is a structure array or a cell array of non-character vectors, anymissing returns false. To determine if any element of a structure array is missing, apply anymissing to each field in the structure by using the structfun function. To determine if any element of a cell array of non-character vectors is missing, apply anymissing to each cell in the cell array by using the cellfun function.

Extended Capabilities

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

Version History

Introduced in R2022a

expand all