0

I have a large CSV data and I tried to import using textscan. The data has some letters NA in the inside the data. I used the following script, however out of 215842 rows only 11 are recognized. The data importing stopped at row where it encouter the NA text.

How could I convert this data to NaN before importing to matlab or other alternative to that might work?

field=fopen ('wt01.csv');

  wt_data= textscan (field,' %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f ','delimiter',',');

fclose (field);
rene
  • 41,474
  • 78
  • 114
  • 152

1 Answers1

0

You can do this using the TreatAsEmpty option, like wt_data= textscan(fid,' %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f ','delimiter',',','TreatAsEmpty',{'NA','na'});

See http://de.mathworks.com/help/matlab/ref/textscan.html

Or use uiimport as it will give you nice buttons to press, including what to do with data that doesn't match the ideal format, and later allow you to generate a script from it, so that you can reuse it.

D.S
  • 116
  • 2
  • That is great and thank you. before reading your message I replaced the NA by some number 99999 outside matlab then I able to import. – Teklehaimanot Jan 05 '16 at 11:07
  • I am sorry D.S, I thought I accepted the answer, the problem is I am not much familar. I hope now accepted otherwise tell me again . – Teklehaimanot Jan 07 '16 at 14:05
  • It isn't marked as accepted. I sadly can't help much with that though, as I haven't asked a question myself yet and thus don't know what the interface looks like, but perhaps [this](http://stackoverflow.com/help/someone-answers) or [this](http://meta.stackexchange.com/questions/147531/how-mark-my-question-as-answered-on-stackoverflow) can help – D.S Jan 07 '16 at 16:22
  • Thank you, now I found it, and it is simple, just click on the gray tick sign to the left of the down facing arrow. – Teklehaimanot Jan 07 '16 at 16:39