How to import only rows containing numbers from a .txt file?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a .txt document that look like this:
etcon,set ! allow ANSYS to choose best KEYOP's for 180x elements
/com,*********** Nodes for the whole assembly *********
nblock,3
(1i9,3e20.9e3)
1 -0.000000000E+000 1.000000000E+002 0.000000000E+000
2 0.000000000E+000 0.000000000E+000 0.000000000E+000
3 1.000000000E+002 0.000000000E+000 0.000000000E+000
4 1.000000000E+002 1.000000000E+002 0.000000000E+000
I only want to import the last 4 rows. How can I do that?
0 commentaires
Réponses (1)
Star Strider
le 14 Sep 2015
Without actually having your file I can’t write exact code for it. This should work, although you may have to experiment with it:
fidi = fopen('text_doc.txt','r');
data = textscan(fidi, '%f%f%f%f', 'HeaderLines',4);
You may need other name-value pair arguments, such as 'Delimiter', 'EndOfLine' and others.
2 commentaires
Star Strider
le 15 Sep 2015
I can’t write code to read the file without having the file to work with.
Attach the file to your original Question, or a Comment to it. (Use the ‘paperclip’ icon, and be sure to do both the ‘Choose file’ and ‘Attach file’ steps.)
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!