reading columns from a text file with errors
Mostra commenti meno recenti
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.
Risposta accettata
Più risposte (3)
Walter Roberson
il 30 Nov 2011
0 voti
Do your columns have fixed width, or do they have a delimiter between the fields?
charles atlas
il 1 Dic 2011
0 voti
charles atlas
il 1 Dic 2011
2 Commenti
Walter Roberson
il 1 Dic 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
il 1 Dic 2011
Categorie
Scopri di più su Data Import and Export in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!