Rounding after using dlmread: how to store exact values?

In some code, I am using the command "dlmread" to get data from ASCII files. To test it, I displayed the matrix of the stored data. When I did this, I found that the data was rounded off to four decimal places in the display? However, most of the data points have more than four decimal places, and I need those numbers.
Does "dlmread" actually round the values? Or is this just a result of displaying the matrix?

댓글 수: 3

Thank you everyone for your input! Here's an update:
After running my script and going into the actual files to confirm that it did what I want, I found that MATLAB has rounded off data points that were not used in the script.
For example, in the very first file, there is a data point that is originally 0.00100962, but after the script runs (even though this point isn't used in any calculations), the file says that the same value is now 0.0010096 (without the last two).
How can I stop MATLAB from doing this to values? It happens with almost every single data point, regardless of whether it is used in the script or not.
Stephen23
Stephen23 2016년 6월 26일
편집: Stephen23 2016년 6월 26일
"I found that MATLAB has rounded off..."
MATLAB does not secretly decide to round values that are stored in its memory. Some operation may be causing this "rounding", or perhaps it is an artifact of displaying those values. In either case we would need to see your code, because otherwise we have to rely on using our crystal balls... and sadly they are just not very reliable.
"How can I stop MATLAB from doing this to values?"
We don't know until we can diagnose and identify what is happening. We can't diagnose without seeing the patient. Ergo, edit your question, click the paperclip button to upload both your code and enough data to run the code and see this effect. Also clearly explain how you view the data to observe this effect.
Exactly what does "the file says" mean? Did you write the array back out to disk with dlmwrite() and you're popping it open with wordpad or something???
Please attach your data file and m script file with the paper clip icon.

댓글을 달려면 로그인하십시오.

답변 (2개)

Star Strider
Star Strider 2016년 6월 26일

0 개 추천

‘Or is this just a result of displaying the matrix?’
Exactly! See the documentation for the format command for the different display options.

댓글 수: 4

So the matrix still has the exact value then? I just want to make sure I do not lose data.
MATLAB retains full internal precision (within the limits of its 64-bit floating point representation) for everything, regardless of what your format display choice is. It will have your data to the precision you read them in.

댓글을 달려면 로그인하십시오.

Image Analyst
Image Analyst 2016년 6월 26일

0 개 추천

댓글 수: 1

I tried using "format long" and it is still rounding off numbers when I don't want it to...

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품

태그

질문:

2016년 6월 26일

댓글:

2016년 6월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by