Text file has headers that are 2X4 and are repeated randomly within the data.

1 回表示 (過去 30 日間)
isamh
isamh 2020 年 2 月 12 日
回答済み: TADA 2020 年 2 月 12 日
txt file is:
R E V D
ms km/h km/h -
689427 0.0 0.00 0.0000
689527 0.0 0.00 0.0000
689627 0.0 0.00 0.0000
689727 0.0 0.00 0.0000
689827 0.0 0.00 0.0000
689927 0.0 0.00 0.0000
690027 0.0 0.00 0.0000
690127 0.0 0.00 0.0000
690227 0.0 0.00 0.0000
headers are repeated randomly across the numerical data. I want to ignore the headers when ever they show up. how would I do that?
the TXT file is about 100000 rows down and 4 columns.
my code is:
result = [];
tic
fid=fopen('MCT_Data.txt');
while 1
tline = fgetl(fid);
if ~ischar(tline), break, end
celldata = textscan(tline,'%f %f %f %f %f %f');
matdata = cell2mat(celldata);
% match fails for text lines, textscan returns empty cells
result = [result ; matdata];
end
toc
fclose(fid);

採用された回答

TADA
TADA 2020 年 2 月 12 日
str = fileread('MCT_Data.txt');
nums = cellfun(@str2double, regexp(str, '([\d.,]+)', 'match'));
x = reshape(nums, 4, [])'
x =
689427 0 0 0
689527 0 0 0
689627 0 0 0
689727 0 0 0
689827 0 0 0
689927 0 0 0
690027 0 0 0
690127 0 0 0
690227 0 0 0

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by