Preserve precision when writing array to csv?

8 visualizaciones (últimos 30 días)
Jeff Leeburn
Jeff Leeburn el 17 de Jul. de 2019
Comentada: Guillaume el 17 de Jul. de 2019
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.
Then I tried this, referencing the question here:
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 comentarios
Jeff Leeburn
Jeff Leeburn el 17 de Jul. de 2019
The other software is ArcGIS 10.6, and I'll have to look into a trailing delimiter character. Attached is an output example from csvwrite that imports fine but lacks the last two decimals of precision in the first column.
Thanks for your help, I appreciate it!
Guillaume
Guillaume el 17 de Jul. de 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.

Iniciar sesión para comentar.

Respuestas (0)

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by