read file from specific position
4 次查看(过去 30 天)
显示 更早的评论
hi,
I have this file:
882359 81 1.5
882359 926 1
882359 1349 2
882359 2270 1
882359 3065 5
I want for example read this file but from third row, i used fseek but not useful thanks
0 个评论
回答(1 个)
Walter Roberson
2011-11-10
There is no way to position directly to particular rows in a text file whose lines are variable length.
Not, that is, without having read it in once first and created an index of where each row begins. (Which can be worth doing if you read the file far more often than you write to it.)
(textscan() has a HeaderLines option, which reads the header lines and throws them away for you.)
5 个评论
Walter Roberson
2011-11-10
Good point, Kelly -- the third field is a floating point number, not a uint8 or the like.
I also see that there are no commas between the fields, such as would be expected by the 'Delimiter', ',' parameter that Huda is using.
Looks like the appropriate command would be
c = textscan(f, '%f%f%f', 'HeaderLines',5);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!