read part of a .txt file
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alberto Acri
el 20 de Ag. de 2024
Comentada: Voss
el 20 de Ag. de 2024
I have the attached .txt file. I would like to read only the lines where the number from 1 to 200 is included.
Each row should be divided into 7 columns: iter | continuity | x-velocity | y-velocity | z-velocity | time | iter.
0 comentarios
Respuesta aceptada
Voss
el 20 de Ag. de 2024
filename = 'file.txt';
str = readlines(filename);
C = arrayfun(@(s)sscanf(s,'%f %f %f %f %f %d:%d:%d %f'),str,'UniformOutput',false);
C(cellfun(@isempty,C)) = [];
M = [C{:}].';
time = duration(M(:,6:8));
M(:,6:8) = [];
names = strsplit(str(1),{' ','/'});
names(strcmp(names,"")) = [];
names{end} = [names{end} '_remaining'];
T = array2table(M,'VariableNames',names([1:end-2 end]));
T = addvars(T,time,'After',names{end-2})
0 comentarios
Más respuestas (1)
Voss
el 20 de Ag. de 2024
filename = 'file.txt';
T = readtable(filename,'CommentStyle','R','NumHeaderLines',0,'VariableNamingRule','preserve');
T(all(isnan(T{:,:}),2),:) = [];
T.Properties.VariableNames([6 7]) = {'time','iter_remaining'};
disp(T)
2 comentarios
Ver también
Categorías
Más información sobre Text Files 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!