remove last line data file
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Antoine van Hirtum
le 9 Déc 2014
Modifié(e) : Geoff Hayes
le 12 Déc 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 commentaires
Réponse acceptée
Geoff Hayes
le 10 Déc 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 commentaires
Geoff Hayes
le 12 Déc 2014
Modifié(e) : Geoff Hayes
le 12 Déc 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Import and Analysis dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!