MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Median 14
Max 563


When you import data from a file, the default is for readtable to read any variables with
nonnumeric elements as a cell array of character vectors.


Find Rows with Missing Values


Display the subset of rows from the table, T, that have at least one missing value.


TF = ismissing(T,{'' '.' 'NA' NaN -99});
rowsWithMissing = T(any(TF,2),:);
disp(rowsWithMissing)


A B C D E




'egh3' NaN 'no' 7 7
'abk6' 563 '' 563 563
'wba3' NaN 'yes' NaN 14
'poj2' -99 'yes' -99 -99
'gry5' NaN 'yes' NaN 21


readtable replaced '.' and 'NA' with NaN in the numeric variables, B, D, and E.


Replace Missing Value Indicators


Clean the data so that the missing values indicated by code -99 have the standard
MATLAB® numeric missing value indicator, NaN.


T = standardizeMissing(T,-99);
disp(T)


A B C D E




'afe1' 3 'yes' 3 3
'egh3' NaN 'no' 7 7
'wth4' 3 'yes' 3 3
'atn2' 23 'no' 23 23
'arg1' 5 'yes' 5 5
'jre3' 34.6 'yes' 34.6 34.6
'wen9' 234 'yes' 234 234
'ple2' 2 'no' 2 2
'dbo8' 5 'no' 5 5


Clean Messy and Missing Data in Tables
Free download pdf