开发者

How to delete headers from different row positions other than at the top - MATLAB

开发者 https://www.devze.com 2023-03-31 13:41 出处:网络
I have a text file that contains multiple headers. It looks like this: Date,time,*10ms,%%,%%,%%,%%,%%,%%,%%,%%,%%,%%,DETAILS.txt;D;%%;10

I have a text file that contains multiple headers. It looks like this:

Date,time,*10ms,%%,%%,%%,%%,%%,%%,%%,%%,%%,%%,DETAILS.txt;D;%%;10
11/08/19,13:19:28,03,446,0,545.75,0,6,0,0,0,14,0
11/08/19,13:19:29,05,446,0,549.25,1.9,6,102,1,0,0,0
11/08/19,13:19:30,07,446,0,549.5,1.9,6,102,1,0,0,0
11/08/19,13:19:31,09,446,0,548.75,1.9,6,102,1,0,0,0
.
.
.
.
Date,time,*10ms,%%,%%,%%,%%,%%,%%,%%,%%,%%,%%,DETAILS.txt;D;%%;10
11/08/19,13:19:28,03,446,0,545.75,0,6,0,0,0,14,0
11/08/19,13:19:29,05,446,0,549.25,1.9,6,102,1,0,0,0
11/08/19,13:19:30,07,446,0,549.5,1.9,6,102,1,0,0,0
11/08/19,13:19:31,09,446,0,548.75,1.9,6,102,1,0,0,0
.
.

and so on...

I would like to write a code that deletes these header-rows and stores the rest of开发者_高级运维 the data to a new file.

Could anyone help with this?

Kind regards,

Tamara


readID = fopen('headers.txt', 'r');
writeID = fopen('no_headers.txt', 'w');
while feof(readID) == 0
    currLine = fgetl(readID);
    if isempty( strfind(currLine, 'Date') )
         fprintf(writeID, '%s\n', currLine);
    end
end
fclose(readID);
fclose(writeID);


It looks like all the headers are the same, I assume you mean: Date,time,*10ms,%%,%%,%%,%%,%%,%%,%%,%%,%%,%%,DETAILS.txt;D;%%;10

And you wish to use MATLAB, if that's the case, you have to open the file, textscan for that one line and then fgetl to remove it.

No need for regex or anything like that when the line is always the same.

0

精彩评论

暂无评论...
验证码 换一张
取 消