I’m reading in a csv file of time-series data into a C++ program. My data however contains
some NaN’s. For example:
1-Jul-2010, 1.0
2-Jul-2010, 2.0
3-Jul-2010, NaN
4-Jul-2010, 3.0
To deal with this I wrote a short script in Matlab which replaces all the NaN’s with 0.0 –
I then read in the new file without the NaN’s. Is there an easy way or avoiding
this pre-processing?
Thanks!
As David Given already mentioned, you do not have to pre-process the file at all. strtof() and strtod() are both able to convert the NaN string to the NaN float/double value.
If you want to replace the values with 0.0 in your dataset, you can do so using the isnan() function.