Change Precision of numbers when saving in csvwrite
44 ビュー (過去 30 日間)
古いコメントを表示
I want to save some data that has one data line which is quite long (e.g.: Data = [12345678, -3.53, 1.52, -0.23; 12345679, -1.43, 6.12, 8.12; 12345680, -0.01, -5.12, -6.13; ...]). I really need the precision of the last digit, but when I use csvwrite the number is cut to 12,345,700. after some searching I found following solution:
csvwrite(FileName, Data, 'precision', '%i')
and it worked at first, but for some reason it stoped working now, which is very confusing to me.
Every time it just gives me an:
Error using csvwrite (line 47)
Invalid attribute tag: ,.
Is there maybe another way I can do it?
4 件のコメント
採用された回答
Walter Roberson
2018 年 3 月 25 日
You are passing 'precision' as your row value, and '%i' as your column value to csvwrite(). csvwrite() then thinks it is passing those to dlmwrite(). dlmwrite() is noticing that they are named options for the purposes of dlmwrite() and is parsing them.
However, there is a bug in current dlmwrite in that if any of the named options are provided then the positional options are not recognized. This is contrary to the dlmwrite documentation and I will file a bug report about that.
I will not, however, file a bug report about csvwrite() because you are misusing it. You should not be using csvwrite() for your purposes. You should be calling dlmwrite() instead
dlmwrite(YourFileName, Data, 'delimeter', ',', 'precision', '%i')
2 件のコメント
Walter Roberson
2018 年 3 月 26 日
dlmwrite(YourFileName, Data, 'delimiter', ',', 'precision', '%i')
その他の回答 (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!