How to pass multiple comment style to skip the header of a text file?
Show older comments
Hi I am pretty new to Matlab, so I need some help. I am trying to read a .txt file by skipping first couple lines (I do not know how many of them I need to skip beforehand). A sample data looks like the following:
<NUMBER OF ZONES 2
<NUMBER OF NODES> 4
<FIRST THRU NODE> 1
<NUMBER OF LINKS> 5
<END OF METADATA>
~ Init node Term node Capacity Length Free Flow Time BPower Speed limit Toll Type;
1 3 1 100 0.00000001 1000000000 1 0 0 1;
1 4 1 100 50 0.02 1 0 0 1;
3 2 1 100 50 0.02 1 0 0 1;
3 4 1 100 10 0.1 1 0 0 1;
4 2 1 100 0.00000001 1000000000 1 0 0 1;
So here, I would like to skip the lines starting with either < or ~. I am using the following codeline:
C = textscan(fid2, '%s' , 'Delimiter', ';', 'CommentStyle' , '<');
And I can skip the first 5 lines. However, I cannot skip the 6th one. I tried to pass multiple commentstyle but it gave an unknown error.
If someone can help me to not read the lines with ~ or <, I'd be glad.
PS: the sample file is easy to see, however, for other files I might not know where exactly the lines that I have to skip are.
Thanks in advance.
Accepted Answer
More Answers (1)
kukushkin
on 26 Feb 2015
0 votes
Categories
Find more on Text Data Preparation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!