Parsing and editing txt file line by line
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Elzbieta
el 19 de Jun. de 2024
Comentada: Voss
el 8 de Jul. de 2024
Hello,
How to automatically transform a txt file in this form by removing strings start and end:
Onset,Annotation
+234.3428079,start
+244.1317829,end
+255.1007751,start
+263.0000000,end
to this form:
+234.3428079,+244.1317829
+255.1007751,+263.0000000
Regards
0 comentarios
Respuesta aceptada
Voss
el 19 de Jun. de 2024
filename_in = 'test.txt';
filename_out = 'test_out.txt';
% show the input file's content, for reference
type(filename_in)
% read filename_in into a table of size n-by-2 containing strings
opts = detectImportOptions(filename_in);
opts = setvartype(opts,opts.VariableNames,'string');
T = readtable(filename_in,opts);
% reshape the first table variable to size n/2-by-2 appropriately,
% and write it to the output file
writematrix(reshape(T{:,1},2,[]).',filename_out)
% check the output
type(filename_out)
4 comentarios
Voss
el 8 de Jul. de 2024
The file has two "starts" in a row, at +2612.0000000 and +2615.0000000, with no "end" in between.
Más respuestas (0)
Ver también
Categorías
Más información sobre Environment and Settings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!