Why is there loss of precision when writing values using CSVWRITE in MATLAB 7.0 (R14)?
55 次查看(过去 30 天)
显示 更早的评论
I execute the following code to write the value '1.23456789' to my CSV-file, as follows:
csvwrite('filename.csv', [1.23456789])
Upon reading the value back from the file, I see that there is some loss in precision:
val = csvread('filename.csv')
val =
1.2346
When I open the "filename.csv" file, it too contains the rounded-off value.
采纳的回答
MathWorks Support Team
2009-6-27
The CSVWRITE function converts numbers to short format before writing them to the file. To preserve precision, use the DLMWRITE function to explicitly set the precision of the data in the CSV-file:
dlmwrite('filename.csv', [1.23456789], 'delimiter', ',', 'precision', 9);
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!