Effacer les filtres
Effacer les filtres

How To Get importdata to Ignore NaN?

9 vues (au cours des 30 derniers jours)
Ian Adler
Ian Adler le 7 Juin 2016
Commenté : Stephen23 le 8 Juin 2016
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

Réponse acceptée

Walter Roberson
Walter Roberson le 7 Juin 2016
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 commentaire
Stephen23
Stephen23 le 8 Juin 2016
Ian Adler's "Answer" moved here:
You're original code did not work for me but using readtable did. Thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Text Data Preparation dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by