フィルターのクリア

how to filter column from a text file

1 回表示 (過去 30 日間)
Hyo Wan Park
Hyo Wan Park 2018 年 9 月 28 日
コメント済み: Stephen23 2018 年 9 月 28 日
I combined two text files into one file.
and then i have to filter column.
For example,
12345 0 123 0.234 0.1234 0.1234 0.123
12345 1 123 0.234 0.1234 0.1234 0.123
12345 1 123 0.234 0.1234 0.1234 0.123
456 5 560 0.123 0.2345 0.5412 0.899
456 8 560 0.123 0.2345 0.5412 0.899
456 8 560 0.123 0.2345 0.5412 0.899
I need two columns skipped and fprintf again in the text file.
Like this,
12345 0.234 0.1234 0.1234 0.123
12345 0.234 0.1234 0.1234 0.123
12345 0.234 0.1234 0.1234 0.123
456 0.123 0.2345 0.5412 0.899
456 0.123 0.2345 0.5412 0.899
456 0.123 0.2345 0.5412 0.899
how can I do that?

採用された回答

Stephen23
Stephen23 2018 年 9 月 28 日
編集済み: Stephen23 2018 年 9 月 28 日
fmt = '%-6d %.3f %.4f %.4f %.3f\n';
mat = dlmread('test_old.txt');
[fid,msg] = fopen('test_new.txt','wt');
assert(fid>=3,msg)
fprintf(fid,fmt,mat(:,[1,4:end]).')
fclose(fid);
Or simply use Notepad++: select those columns using shift+alt, then press delete.
  2 件のコメント
Hyo Wan Park
Hyo Wan Park 2018 年 9 月 28 日
Thanks a lot!!!! it's so perfect answers to me.
Stephen23
Stephen23 2018 年 9 月 28 日
Another option would be to read the file using textscan, with string format specifiers. Then you could retain exactly the same character data that the first file contains.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by