MATLAB: How to filter column from a text file

columnstext filetextfile

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?

Best Answer

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.