How to import only rows containing numbers from a .txt file?
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Star Strider
on 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 Comments
Star Strider
on 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.)
See Also
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!