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

4 ビュー (過去 30 日間)
Ermin Sehovic
Ermin Sehovic 2015 年 9 月 14 日
コメント済み: Star Strider 2015 年 9 月 15 日
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?

回答 (1 件)

Star Strider
Star Strider 2015 年 9 月 14 日
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 件のコメント
Ermin Sehovic
Ermin Sehovic 2015 年 9 月 15 日
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 2015 年 9 月 15 日
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.)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by