필터 지우기
필터 지우기

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 CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by