how to extract specific rows of a .txt file ?
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ivan Mich
el 13 de Dic. de 2022
Comentada: Voss
el 15 de Dic. de 2022
I have a problem with a code. I have a file with several rows and columns. Some rows, especially the first six numbers of them, are repeated line by line.
I want a final output that includes only the rows of which the first 6 numbers are repeated.
for example I attach an example of the input and of the output of what I mean
could you please help me?
0 comentarios
Respuesta aceptada
Voss
el 13 de Dic. de 2022
M = readmatrix('input.txt');
M(:,end) = [];
[~,~,jj] = unique(M,'rows','stable');
M([false; diff(jj) == 0],:) = [];
writematrix(M,'output.txt','delimiter','\t');
% check the output file:
type output.txt
2 comentarios
Voss
el 15 de Dic. de 2022
M = readmatrix('input.txt');
M(:,end) = [];
[~,~,jj] = unique(M,'rows','stable');
M([false; diff(jj) == 0],:) = [];
M(:,end+1) = diff(find(diff([0; jj; 0])));
writematrix(M,'output.txt','delimiter','\t');
% check the input and output files:
type input.txt
type output.txt
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!