フィルターのクリア

Reading exact line numbers from a file?

2 ビュー (過去 30 日間)
David Pesetsky
David Pesetsky 2016 年 6 月 2 日
回答済み: Walter Roberson 2016 年 6 月 2 日
Hi,
I'm using
C260=textscan(fid2, '%s', 1, 'delimiter', '\n', 'headerlines', 466-1);
...to read a specific line number. Now I realize if I want to read another specific line number, say 401, the pointer is in the wrong place, and Headers I think just advances it. Can I pinpoint any line number, in no specific order, and pull it out?
Thanks a lot, Dave

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 6 月 2 日
textscan is always relative to the current position in the file. You can use fseek to rewind to the beginning of the file.
Positioning by line number is very inefficient. However if you are going to process a file multiple times then it can be effective to build an index of line numbers and corresponding offsets in the file which ftell can tell you.

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by