anymissing - Determine if any array element is missing - MATLAB (original) (raw)
Determine if any array element is missing
Since R2022a
Syntax
Description
`TF` = anymissing([A](#mw%5F0ec2883e-146f-455f-b629-ac3352f01f5d))
returns logical 1
(true
) if at least one element ofA
is missing. It returns 0
(false
) if no element is missing.
Missing values are defined according to the data type ofA
:
NaN
—double
,single
,duration
, andcalendarDuration
NaT
—datetime
<missing>
—string
<undefined>
—categorical
{''}
—cell
of character vectors
If A
is a table, then the data type of each variable defines the missing value for that variable.
For data types with no default definition of a standard missing value,anymissing
returns logical 0
(false
).
Examples
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)
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 {0×0 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.
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
Input Arguments
Input data, specified as a scalar, vector, matrix, multidimensional array, cell array of character vectors, table, or timetable.
- If
A
is a timetable, thenanymissing
operates on the table data only and ignoresNaT
orNaN
values in the row times. - If
A
is a cell array, thenanymissing
only detects missing elements whenA
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
returnsfalse
. To determine if any element of a structure array is missing, applyanymissing
to each field in the structure by using thestructfun
function. To determine if any element of a cell array of non-character vectors is missing, applyanymissing
to each cell in the cell array by using thecellfun
function.
Extended Capabilities
Theanymissing
function fully supports tall arrays. For more information, see Tall Arrays.
The anymissing
function fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced in R2022a
Character arrays have no default definition of a standard missing value. Therefore,anymissing
treats blank character array elements (' '
) as nonmissing. For example, anymissing(['a'; ' '])
returns logical 0
. Previously, it returned logical 1
.