From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: How to import data without losing much precision
Date: Sun, 2 Dec 2012 22:19:08 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 45
Message-ID: <k9gk4s$2hh$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1354486748 2609 (2 Dec 2012 22:19:08 GMT)
NNTP-Posting-Date: Sun, 2 Dec 2012 22:19:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2105620
Xref: comp.soft-sys.matlab:783992

I'm trying to import some data, which was created by C code, into Matlab without losing much precision. Can someone show me an example of how to do so?

I have about 52 decimal places of precision, with N=16 numbers on a line, like this:


I've tried using dlmread, csvread and importdata, but they cut off precision.

Now I am trying to use textread, because the format string specifier might let me keep precision. But I have not had any luck. I tried following example 4 in the documentation:

EDU> data=textread('u1.csv.txt', '%60.51f', 16, 'delimiter', ',');
EDU> sprintf('%.20e', data(2,1))
ans =

EDU> data=textread('u1.csv.txt', '%f', 'delimiter', ',')
(doesn't import data as a matrix)
EDU> sprintf('%.20e', data(2,1))
ans =

EDU> data=textread('u1.csv.txt', '%f', 16, 'delimiter', ',')
(reads only one line, but there's probably a way to read the "next" line)
sprintf('%.20e', data(2,1))
ans =

I've tried other things, too, but I cannot get any more precision. You can see that their all losing precision after about 16 decimal places.

I have (and can create) other formats for the input file. Other formats that I have are u1.fixedWidth.txt and, which look like you'd expect them to look (u1.fixedWidth is printed with "%60.52f" and is printed as "%.52f\t"). But this also loses precision:

EDU>> data=textread('u1_0000000.fixedWidth.txt', '%60.52f', 16);
EDU>> sprintf('%.20e', data(2,1))
ans =

Could someone show me an example of how to import my data with the most precision?
Thanks you.

Note that I am using student version of Matlab R2009a (and cannot upgrade it) on a 64-bit Windows 7 machine. I don't really know how much precision my version of Matlab has (or how to find out).