How to import only rows containing numbers from a .txt file?

2 views (last 30 days)
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?

Answers (1)

Star Strider
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
Ermin Sehovic
Ermin Sehovic on 15 Sep 2015
The file is called "Plate.dat". When I try that code the output is:
data = [0x1 double] [0x1 double] [0x1 double] [0x1 double]
and not a 4x3 matrix as I would like to.
Star Strider
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.)

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!