How to skip lines when reading a text file that start with specific input?
이전 댓글 표시
Hi -
I'm working on reading in a text file of accumulated data, but the headerlines are always printed with the data. For example, the beginning of each line in the text file looks like:
"TOA5","CapeBird","CR1000",
"TIMESTAMP","RECORD",
"TS","RN","","","","",
"","","Smp","Smp","Smp"
"2014-10-01 00:10:00",
"2014-10-01 00:20:00",
"2014-10-01 00:30:00",
"TOA5","CapeBird","CR1000",
"TIMESTAMP","RECORD",
"TS","RN","","","","",
"","","Smp","Smp","Smp"
"2014-10-01 00:40:00",
"2014-10-01 00:50:00",
"2014-10-01 01:00:00",
.....
I've found examples where you can specify to not read in strings through the "textscan" function, but as you can see, everything is a string. The data I want read in starts with the dates "2014-10-01..." and I want to eliminate the 4 lines that have words or just empty double quotes. The header will always be exactly the same... it's a very long line of text, so I'm not sure if that complicates this, or if I can just find the first phrase/word and eliminate the entire line. Also, the data is not always consistent and will not always come in lines of 3 (sometimes more, sometimes less), so I can't just skip 4 lines, read in 3, skip 4 lines, etc.
If anyone knows how I can delimit or just eliminate these 4 header lines by somehow checking for a word/phrase/entire line, that would be incredibly helpful. Long story short, when the line is NOT one of the header lines, I need this to work:
textscan(file,'%s %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f', ...
'delimiter',',','EmptyValue',nan, 'headerLines',4,'TreatAsEmpty','"NAN"')
Thanks!
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!