reading columns from a text file with errors
Ältere Kommentare anzeigen
I have a code displayed below
clear
clc
file1=input('enter file name in single quotes ');
fid = fopen(file1,'rt');
X = textscan(fid,'%s%s%f%s%s%s%f%f%f%f%s%s%s%s',...
'HeaderLines',7);
fclose(fid);
time= X{1}; status = X{6}; length=X{10};
This reads data i need from a file so that I can analyze it. The problem wiht this code is that sometimes the 4th column of data has one word of text and sometimes it has two.
the 4th column would look like this:
X{4}=
'heating'
'heating'
'heating'
'heating'
'cooling down'
etc.
When matlab reads the file it gets to the row that says 'cooling down' in the 4th column and thinks that 'down' is another column. textscan stops working at that point and I only get the data up to the point where the row that says 'cooling down' appears.
Is there any way to merge the words cooling down to say 'coolingdown' so that the code will read all of the data? Or is there another alternative? I need to read all of the data from this file. I do not care what happens to the 4th column, because I am not interested in the data from it but I need the other columns of data.
Akzeptierte Antwort
Weitere Antworten (3)
Walter Roberson
am 30 Nov. 2011
0 Stimmen
Do your columns have fixed width, or do they have a delimiter between the fields?
charles atlas
am 1 Dez. 2011
0 Stimmen
charles atlas
am 1 Dez. 2011
2 Kommentare
Walter Roberson
am 1 Dez. 2011
That *is* fixed-width columns. That makes the task easier in some ways.
Unfortunately I have an appointment to go to now and cannot show appropriate code at this time.
charles atlas
am 1 Dez. 2011
Kategorien
Mehr zu Data Import and Export finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!