www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/SpecifyIndicatorsforMissingValuesinTableExample.m

    %% Specify Indicators for Missing Values in Table  
% Create a table where |'NA'|, |''|, |-99|, |NaN|, and |Inf| represent missing
% values. Then, find the elements with missing values.   

%%  
dblVar = [NaN;3;Inf;7;9];
int8Var = int8([1;3;5;7;-99]);
cellstrVar = {'one';'three';'';'NA';'nine'};
charVar = ['A';'C';'E';' ';'I'];

A = table(dblVar,int8Var,cellstrVar,charVar)  

%% 
% |ismissing| returns 1 where the corresponding element in |A| has a missing
% value. 
id = {'NA' '' -99 NaN Inf};
TF = ismissing(A,id) 

%%
% |ismissing| ignores trailing white space in character arrays. Therefore,
% since the empty character vector, |''|, is specified as a missing value indicator,
% |ismissing| identifies the empty character vector in |A.cellstrVar| 
% and also the blank space in |A.charVar| as missing values.