reading columns from a text file with errors
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (3)
Walter Roberson
el 30 de Nov. de 2011
0 votos
Do your columns have fixed width, or do they have a delimiter between the fields?
charles atlas
el 1 de Dic. de 2011
0 votos
charles atlas
el 1 de Dic. de 2011
2 comentarios
Walter Roberson
el 1 de Dic. de 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
el 1 de Dic. de 2011
Categorías
Más información sobre Data Import and Export en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!