MATLAB: How to read a row/column which has only NaNs using importdata

columnsimportdataMATLABnan'srows

When I try to import the following data into MATLAB workspace from a space delimited text file 'test_file.txt'
0 6 NaN NaN NaN
3 6 3.7 NaN NaN
4 4 NaN NaN NaN
NaN NaN NaN NaN
using the command:
importdata('testfile.txt')
I receive the following:
0.0000 6.0000 NaN
3.0000 6.0000 3.7000
4.0000 4.0000 NaN
The rows and columns with only NaNs are not read from the file.

Best Answer

The ability to read NaN values is not available in MATLAB.
When the input file has rows and columns with all NaNs, then the importdata function does not read all the values from the file.
As a workaround use the TEXTSCAN function to read the data.
data_temp = cell2mat(textscan(fopen('test_file.txt'),'%f %f %f %f %f'));