Weird error when importing ascii file data
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Try to import an ascii data file that looks like this:
# 1-8-2016 14:13:43
# 1452258823
# 1
# 0
# 1
# 2.4414e-005
# -2.0270e-003
# 2.7100e+000
# 5669
0 4095
0 4095
0 4095
0 4095
0 4095
0 4095
0 4095
0 4095
0 4095
1 4095
2 4095
3 4095
4 0
5 971
6 973
7 979
8 989
9 998
10 1002
11 1007
12 1008
13 1011
14 1013
Using dlmread ignoring the first 9 lines:
Rdata=dlmread(filename,' ',9,0);
It looks as it is working fine,it ignores the first 9 rows, however the first values in the Rdata are NOT the same as in the ascii file (showing again as code for the better format):
0 1002
0 1002
0 1002
0 1002
0 1002
0 1002
0 1002
0 1002
1 1002
2 1002
3 1002
4 1002
5 1002
6 1002
7 1002
8 1002
9 1002
10 1002
11 1007
12 1008
13 1011
14 1013
So the 2th column values of 4095 are overwritten with 1002. But a couple of rows below it starts to pick up the real values as shown in the ascii file.
What am I doing wrong here?
P.S. Reading the same ascii file in Python works fine.
2 commentaires
Réponses (1)
Walter Roberson
le 7 Avr 2016
We noticed in the R2015b time frame that the documentation of dlmread() had changed slightly, without a corresponding Release Notes change. The change might have happened in R2015a instead of R2015b. We do not think the change was there as early as R2014b.
In earlier versions, text was not permitted in files read by dlmread(), not even in rows or columns that were being requested to be skipped. The change was to allow text in the portions being skipped.
So, the difference between what Adam sees and what you see might have to do with your respective versions. Which version are you using?
To be more robust you should switch to textscan(), or (if you have R2013b or later) readtable.
Voir également
Catégories
En savoir plus sur Data Import and Export dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!