
Write NaN to file when exporting data

kaikin
Hello,
Is it possible to write NaN to a file when exporting data using the Save or SaveTableCopy operations rather than leaving the field blank for example when writing to a csv file? If not, is that a possible flag to add?
I have no quick code to test this, but I think you should get NaN if you convert the data to text before saving. This could be achieved easily in a script, where all waves from the selected table are collectively written into a temporary text wave before invoking the save command. What do you want to do with the data once it's written? I believe NaN has a quite strict definition and just writing the text 'NaN' in a csv file, for example, serves only a very limited purpose (namely that you can read it in a text editor).
April 19, 2022 at 09:49 am - Permalink
Hi Kaikin
You can do this with wfprintf also, like in the example below. AFAIK wfprintf can take several (many) waves as input to make a table. At least in Igor 9 wfprintf is also very fast even for large datasets too.
April 19, 2022 at 01:14 pm - Permalink
Thanks, both good suggestions and worked just fine. I've just run into a couple of cases where a colleague who sadly didn't use Igor needed to read a file that I was exporting and requested actual NaNs.
April 19, 2022 at 01:28 pm - Permalink
You can write a routine that replaces ",," with ",NaN," and replaces ",<terminator>" with ",NaN<terminator>".
Here is some untested code that is based on this code snippet:
April 19, 2022 at 02:52 pm - Permalink
Or run a (text editor) REGEX function on the CSV text file to replace strings ",,", ",\r" and ",\f" with ",NaN,". :-)
April 19, 2022 at 04:01 pm - Permalink
If you want to export or write a numeric NaN, you could try one of the IEEE bit-wise representations.
A simple solution in Igor Pro is to assign the numeric value 0/0. From the command line,
print 0/0
gives NaN.
April 20, 2022 at 02:50 am - Permalink