read file from specific position

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

답변 (1개)

Walter Roberson
Walter Roberson 2011년 11월 10일

0 개 추천

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

huda nawaf
huda nawaf 2011년 11월 10일
but in textscan will return just one line
ex.
c = textscan(f, '%f %f %su', 'Delimiter', ',', 'headerLines', 5);
will return just sixth row, I want from 6 to last row
thanks
Walter Roberson
Walter Roberson 2011년 11월 10일
textscan() will *not* return just one line. On the other hand, your textscan would be failing because you are attempting to match the literal character 'u' as a fourth field, with the third field being a string. There is no %su format item. If you want your third field to be read as an unsigned 8 bit integer, use %u8 as the format item.
http://www.mathworks.com/help/techdoc/ref/textscan.html
Kelly Kearney
Kelly Kearney 2011년 11월 10일
Textscan will read until either the end of the file, or until the format specifier no longer matches the text it's trying to parse. I'm not sure what you really meant by the '%su' format, but that's probably what textscan is stumbling over.
Your example data doesn't seem to match your example textscan line, so I can't help you figure out what the format should be.
Walter Roberson
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);
huda nawaf
huda nawaf 2011년 11월 10일
thank u very much for all .
in fact i'm not see %su, it is just error in print.
i'm so sorry
thanks again

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

태그

질문:

2011년 11월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by