remove last line data file
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Antoine van Hirtum
el 9 de Dic. de 2014
Editada: Geoff Hayes
el 12 de Dic. de 2014
A MATLAB script is made to load data from a .xyz file into the workspace. The datafile consists of three columns of numbers, the number of lines varies per file, about 800 to 1000 lines. However, the file has also text which I would like to ignore. I would like to make a script that automatically removes/ignores the text in the file. How to get rid of the last line of the file? 1 1 1 2 4 0 6 8 0 . . . . . . . . . tekst Thanks for your answer, - A
0 comentarios
Respuesta aceptada
Geoff Hayes
el 10 de Dic. de 2014
Antoine - if you are interested in removing the last line from the file (which includes non-numeric text), then try using importdata which seems to ignore the last line if it isn't numeric. For example, if your text file, test.txt, has the following contents
12 12 12
13 13 13
14 14 14
15 15 15
a final line with non-numeric text
then
data = importdata('test.txt')
returns
data =
12 12 12
13 13 13
14 14 14
15 15 15
Try the above and see what happens!
2 comentarios
Geoff Hayes
el 12 de Dic. de 2014
Editada: Geoff Hayes
el 12 de Dic. de 2014
Check the documentation for this function and look at the headerLinesIn input parameter. You could try using it as follows
fileData = importdata('test.txt',' ' ,14);
where ' ' indicates that row element is using the space character as the delimiter, and 14 is the number of header lines. So if your text file now looks like
a
b
c
d
e
f
g
h
i
j
k
l
m
n
12 12 12
13 13 13
14 14 14
15 15 15
a final line with non-numeric text
then calling the above line of code will set fileData to be a structure with two fields - the numeric data, and the alphabetic textdata. So
fileData.data =
12 12 12
13 13 13
14 14 14
15 15 15
Try experimenting with the importdata function.
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Import and Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!