How to maintain the precision of data?

3 views (last 30 days)
nl2605
nl2605 on 25 Jul 2013
I am working with data in the range of microns and although I can read it from the text file with precision, when I work with the data in Matlab, the data isn't as precise as anymore. For example:
I start with data like : -432.731805 612.208233 1234.20203
I am using textscan to read it and then converting it into matrix using cell2mat.
The resulting calculations degrade in precision. I get output as:
648.000000 1314.000000
This is meaningless to me. Could anybody tell me how to retain the precision?
Thanks a lot.
  12 Comments
dpb
dpb on 30 Jul 2013
Edited: dpb on 30 Jul 2013
It's both... :)
Under Windows, the newline character is actually two characters \r\l whereas on unix-like OS it is simply one. Once upon a time virtually all Windows programs expected the two-character sequence and it was a very big pain in the proverbial appendage to transfer files owing to the difference.
One of the prime symptoms of not using the two on Windows is that of the "run on" of lines in editors, etc., that you're seeing if those programs were written w/ the expectation that all files would have the Windoes-defined 2-character sequence. Notepad is one of those.
With time, programs began to take care of the problem behind the scenes as does Matlab internally on input or in its builtin editor. Notepad is about the only widely used text editor left on mass distributions that still has the old-timey behavior.
You can solve the problem one of two basic ways...
a) Use something other than Notepad--generally the recommended approach; there are many options; Wordpad would be one.
b) If you think you must continue w/ Notepad, then when you write files that are going to be used with it, write them with the proper linefeed for the OS. To do this most easily in/with Matlab use the 't' option on the fopen statement.
fid=fopen('yourtextfile', 'wt');
See
doc fopen
for more details.
nl2605
nl2605 on 30 Jul 2013
Crazy!!!! Thanks a lot! :)

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!