Preserve precision when writing array to csv?
8 views (last 30 days)
Show older comments
Hi, I have a simple script that converts geographic data in polar cylindrical coordinates to decimal degrees. The output is a very large 3 columns by ~1.5 million rows array to 4 decimals precision. This inconvenient format is necessary because of the software (ArcMap) the output csv needs to be imported into.
First I tried this:
format long g
csvwrite(fileout,data);
fclose('all')
The result imports perfectly, but the longitude values (the first array column) are truncated to 2 decimal places.
dlmwrite(fileout, data, 'delimiter', ',', 'precision', 7);
fclose('all')
The output looks perfect in both matlab and excel, but is missing the second column upon import into the other software. Because of the large number of rows, I can't edit or resave in excel to try to fix whatever this problem is.
Finally I tried simply
writematrix(data, fileout)
fclose('all')
but the lines run, proceeds to completion very quickly without error, and does not write a file.
I'm out of ideas. Am I missing an alternative here, or is there something in my dlmwrite line that might have caused problems?
Thanks!
4 Comments
Guillaume
on 17 Jul 2019
There is nothing wrong with your dlmwrite call, so the problem is with ArcGIS. Maybe the software documentation can enlighten you as to what format it expects.
writematrix(data, fileout) should write a file or error. Are you sure you're looking in the right folder for the file? The simplest way to avoid confusion over which folder the file is written in is to use absolute paths.
Answers (0)
See Also
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!