MATLAB: Readtable of csv with empty cells gives NaN and ‘ ‘

csvMATLABnanreadtable

I want to read from a huge csv file. some cells are empty. sometimes matlab puts in NaN for an empty cell and sometimes it just puts in ' '. I would like to always have NaN.

Best Answer

detectImportOptions and setvartype() to 'double' and readtable using the options
What is happening is that columns that are completely empty, MATLAB detects as text columns that are empty. When a column is detected as having numeric elements but no nonempty text then it will be stored as double and nan will be used.