フィルターのクリア

How to delete header lines at the beginning and from the middle of a text file

2 ビュー (過去 30 日間)
Hello
I have a text file which contains data in the following way -
Series_1_2
Sweep_1_2_1 5.362E+04 2018/04/03 14:53:42.633
"Index" "Time[s]" "Imon-1[A]" "Time[s]" "Emon-1[V]"
0 0 -9 0 4
1 1 -9 1 5
2 2 -8 2 5
3 3 -9 3 5
Sweep_1_2_2 5.364863300E+04 14:54:08.633 2018/04/03 14:53:42.633
"Index" "Time[s]" "Imon-1[A]" "Time[s]" "Emon-1[V]"
0 0 -9 0 4
1 1 -9 1 5
2 2 -8 2 5
3 3 -9 3 5
I want to delete all the extra header lines and the empty lines in there and just keep the 5 columns of data so it looks like
0 0 -9 0 4
1 1 -9 1 5
2 2 -8 2 5
3 3 -9 3 5
0 0 -9 0 4
1 1 -9 1 5
2 2 -8 2 5
3 3 -9 3 5
I tried using regexprep, but was not successful.
Thanks in advance.

採用された回答

Walter Roberson
Walter Roberson 2018 年 4 月 7 日
S = fileread('YourFile.txt');
wanted = regexprep(S, {'^\S.*$\n','^$\n'}, {'',''}, 'lineanchors', 'dotexceptnewline');
  3 件のコメント
Swathi Putchakayala
Swathi Putchakayala 2019 年 4 月 10 日
but i need only the rows and coloums of the above data. But not the whole thing in that document.
Walter Roberson
Walter Roberson 2019 年 4 月 10 日
Perhaps your input does not exactly match the one that I wrote this code for. I designed this code for the case where the unwanted lines all begin with a character that is not whitespace.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by