필터 지우기
필터 지우기

How To Get importdata to Ignore NaN?

조회 수: 9 (최근 30일)
Ian Adler
Ian Adler 2016년 6월 7일
댓글: Stephen23 2016년 6월 8일
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