Increasing precision when parsing float values using textread()
이전 댓글 표시
Hello,
I am using textread() function to parse text values; I have the following line which works well:
[V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14] = textread(file_1,'%f %f %f %f %f %f %f %f %f %f %f %f %f %f','headerlines',5);
The problem I am facing is that float values in the original text contain 6 digits after decimal point, while textread() returns only 4 digits after the decimal point.
For example:
Original value: -0.785834
Value returned by textread(): -0.7858
Please, suggest how to get the full precision of floats when using textread()
Thanks in advance
댓글 수: 1
Iain
2014년 10월 13일
Are you sure that the value returned is EXACTLY -0.7858, or is that just what matlab is displaying?
채택된 답변
추가 답변 (1개)
The help page (R2014b) suggests you should use textscan now instead of textread, but I assume the following works for either while textread still exists.
You can specify the precision you want for your floats by e.g.
%.6f
to specify the number of values after the decimal place.
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!