How to import only rows containing numbers from a .txt file?
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
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 件のコメント
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 Exchange で Data Import and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!