MATLAB: How to avoid truncation and loss of precision when saving the data in MATLAB

asciibinarydatalossMATLABprecisionsavesavingtruncation

I have tried saving my data with SAVE -ASCII (or FPRINTF, DLMWRITE, etc.) and notice that I lose precision when I do this.

Best Answer

To obtain 16-digit ASCII format using the SAVE function, use the following command:
save -ascii -double
Following is an example of writing "pi" to a TXT-file with double precision using DLMWRITE:
dlmwrite('myfile1.txt', pi, 'delimiter', '\t', 'precision', 16)
For more information on precision specification, refer the respective documentation pages by executing the following MATLAB commands:
doc save
doc dlmwrite
Information on C-style format string allowed in DLMWRITE can be found here:
doc sprintf
Related Question