I have a short, but time-eating problem. I have to read out a text-
file with 3 columns. The problem is that first column has a lot of
positions after the decimal point and mfscanf doesn't read in
correctly:
For example:
-3.2428714E-03,-3.06E-01,-9.0E-03
-3.2428614E-03,-2.99E-01,-7.4E-03
-3.2428514E-03,-3.19E-01,-5.0E-03
-3.2428414E-03,-3.34E-01,-4.8E-03
-3.2428314E-03,-3.37E-01,-1.21E-02
-3.2428214E-03,-3.04E-01,-2.44E-02
I read in this file with this code:
fd = mopen('Test.txt','r');
[n,a,b,c] = mfscanf(-1,fd, ' %f,%f,%f ' );
mclose(fd);
The result of the first column:
-->a
a =
- 0.0032429
- 0.0032429
- 0.0032429
- 0.0032428
- 0.0032428
- 0.0032428
-->a(1) + 3.2428714E-03
ans =
- 9.124D-11
As you can see, the values are wrong.
Can anybody help me???
Best regards,
Fritz
please do
help format
and then
format(16)
a
> The result of the first column:
>
> -->a
> a =
> - 0.0032429
> - 0.0032429
> - 0.0032429
> - 0.0032428
> - 0.0032428
> - 0.0032428
>
> -->a(1) + 3.2428714E-03
> ans =
> - 9.124D-11
>
> As you can see, the values are wrong.
>
> Can anybody help me???
>
> Best regards,
> Fritz
--
Helmut Jarausch
Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
You know that -9.12E-11 is a order lower than the your number which
has an accuracy of 1E-10. Perhaps you could set the values of the
matrix to zero before you fill them with your number. Not sure this
will work.
Francis
Was a good hint, but didn't really solve my problem:
-->format(16)
-->a
a =
- 0.0032428714912
- 0.0032428614795
- 0.0032428514678
- 0.0032428414561
- 0.0032428314444
- 0.0032428214327
Does scilab fill up the last digits with random numbers?? In my file
are 3 digits less than I got here!?!
My problem is, that I have not just 6 lines, I have 1.000.000 lines
(35MB file) and the first column is the time stored by the agilent
oscilloscope. So there should be 1e-8 steps between each value.
Thanks for your help!
Fritz
Hallo Fritz,
What's about this solution with read()?
--> format('e',14)
--> a=read('Test.txt',-1,3)
a =
- 3.2428714D-03 - 3.0600000D-01 - 9.0000000D-03
- 3.2428614D-03 - 2.9900000D-01 - 7.4000000D-03
- 3.2428514D-03 - 3.1900000D-01 - 5.0000000D-03
- 3.2428414D-03 - 3.3400000D-01 - 4.8000000D-03
- 3.2428314D-03 - 3.3700000D-01 - 1.2100000D-02
- 3.2428214D-03 - 3.0400000D-01 - 2.4400000D-02
Helmut
Hi,
The value you read are correct since you are reading in simple
precision (float)
you would have the same result with the fscanf performed at C level
If you want double precision you have to use %lf and not %f
[n,a,b,c] = mfscanf(-1,fd, ' %lf,%lf,%lf ' );
...
format(16)
-->a
a =
- 0.0032428714
- 0.0032428614
- 0.0032428514
- 0.0032428414
- 0.0032428314
- 0.0032428214
Since scilab only use double precision internally %lf could be
performed
internally when a user specify %f.
jpc
Hi guys!
Thanks a lot for your solutions!!!!!
Best regards,
Fritz