Borrar filtros
Borrar filtros

how to filter column from a text file

1 visualización (últimos 30 días)
Hyo Wan Park
Hyo Wan Park el 28 de Sept. de 2018
Comentada: Stephen23 el 28 de Sept. de 2018
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?

Respuesta aceptada

Stephen23
Stephen23 el 28 de Sept. de 2018
Editada: Stephen23 el 28 de Sept. de 2018
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 comentarios
Hyo Wan Park
Hyo Wan Park el 28 de Sept. de 2018
Thanks a lot!!!! it's so perfect answers to me.
Stephen23
Stephen23 el 28 de Sept. de 2018
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.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by