read part of a .txt file
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Voss
2024 年 8 月 20 日
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 件のコメント
その他の回答 (1 件)
Voss
2024 年 8 月 20 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Text Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!