textscan question skip lines
82 ビュー (過去 30 日間)
I'm using textscan to import a non rectangular data text file. I'm having an issue skipping lines. The file has 10 rows at the begining which I'd like to skip, and for that I use the HeaderLines option.
fid = fopen('test.txt');
c = textscan(fid,'%s%d %d %d %d %d %d','HeaderLines', 10 );
The rest of the text file periodically, every 50 lines has a few lines that I'd also like to skip, this is where I'm running into a problem. Any ideas?
回答 (2 件)
Walter Roberson 2013 年 1 月 29 日
When you textscan, add a count after the format. The count will be the number of times the format is re-applied, and thus limits the number of lines read with that textscan() call. You would then loop around doing such calls and splicing the data together.
In some cases you can make use of the CommentStyle parameter to cause textscan() to automatically skip parts of the input. For example, if each of the lines to be skipped started with ';' you could set CommentStyle to ';' and the lines would be skipped. If this case applies to you, you would not need to put a count on or splice the data together.