reading columns from a text file with errors
Show older comments
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.
Accepted Answer
More Answers (3)
Walter Roberson
on 30 Nov 2011
0 votes
Do your columns have fixed width, or do they have a delimiter between the fields?
charles atlas
on 1 Dec 2011
0 votes
charles atlas
on 1 Dec 2011
2 Comments
Walter Roberson
on 1 Dec 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
on 1 Dec 2011
Categories
Find more on Data Import and Export in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!