How To Get importdata to Ignore NaN?

9 次查看(过去 30 天)
i have a text file that looks like this: (attached for reference)
"2014-01-01 23:56:00",3620609,37.8,23.83333,760.9666,11.375,815.4666,0,71493.23,1
"2014-01-01 23:56:30",3620610,41.66667,23.8,761,"NAN","NAN",0,"NAN",1
"2014-01-01 23:57:00",3620611,39.86666,23.73333,760.9666,11.375,815.5999,0,71593.27,1
my code is simply
a=importdata('TEST.txt');
And a becomes a struct.
looking at a.data, it only has two rows, and the third row (along with any other rows) just gets clipped off. How do I get the code to import the next lines? My resultant a.data is below by the way
3620609 37.8000000000000 23.8333300000000 760.966600000000 11.3750000000000 815.466600000000 0 71493.2300000000 1
3620610 41.6666700000000 23.8000000000000 761 NaN NaN NaN NaN NaN

采纳的回答

Walter Roberson
Walter Roberson 2016-6-7
fid = fopen('TEST.txt', 'rt');
datacell = textscan(fid, '%q%f%f%f%f%f%f%f%f%f', 'Delimiter', ',', 'TreatAsEmpty, '"NAN"');
fclose(fid)
You might want to use %D instead of %q if you have R2014b or later; that would convert the date/time into datetime objects
If your version of MATLAB is too old for %q then you can use
'"%[^"]"%f%f%f%f%f%f%f%f%f'
You could also consider using readtable()
  1 个评论
Stephen23
Stephen23 2016-6-8
Ian Adler's "Answer" moved here:
You're original code did not work for me but using readtable did. Thanks

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Text Data Preparation 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by