Weird error when importing ascii file data

5 vues (au cours des 30 derniers jours)
Q3V
Q3V le 6 Avr 2016
Commenté : Q3V le 7 Avr 2016
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
Adam
Adam le 6 Avr 2016
Modifié(e) : Adam le 6 Avr 2016
Strange. It gives me the correct data if I paste your data into a file and read that in using your code. Is this literally the only line of code you are running when testing this?
Q3V
Q3V le 7 Avr 2016
Tried the same as you and you are right, it works ok on itself. So the issue will be due to the rest of the code: The full code:
if true
FilterSpec='*.par';
DialogTitle= 'Select T3Star measurement file';
[FileName,PathName,FilterIndex]=uigetfile(FilterSpec,DialogTitle,workdir);
file_name=[PathName '\' FileName];
ParID=fopen(file_name,'r');
dheader=textscan(ParID,'%s',3,'Delimiter','\n');
dtitle=textscan(ParID,'%s',1,'Delimiter','\n');
dbody=textscan(ParID,'%s %f','Delimiter','=');
dinterm=textscan(ParID,'%s',2,'Delimiter','\n');
dpower=textscan(ParID,'%s %f','Delimiter','=');
lsb=dbody{1,2}(4);
k_in=dbody{1,2}(5);
Vf_in=dbody{1,2}(6);
power=dpower{1,2};
title=cell2mat(dtitle{:});
fclose(ParID);
RawFile=strrep(FileName,'par','rec');
raw_name=[PathName '\' RawFile];
Rdata=dlmread(raw_name,' ',10,0)
end

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
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.
  1 commentaire
Q3V
Q3V le 7 Avr 2016
We are using R2015b. readtable does not work as the file I want to read has not a txt extension. textscan has the same issue and gives the wrong values....

Connectez-vous pour commenter.

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!

Translated by