On 3/26/2013 2:38 PM, Wanderson wrote: ...[ don't toppost, though-- hard follow conversation makes]...
> "Wanderson " <firstname.lastname@example.org> wrote in message > <email@example.com>... >> Hi, I'm having a trouble dealing with the function textscan. >> >> In fact, I want to use that function twice inside the same script. For >> example, I need to read one entire file called 'test.txt' and later in >> my code I want to read just the end of the file and I thought to use >> the textscan again with the HeaderLines parameter. >> >> If my test.txt file were formatted it will be easier, but I have >> something like that: >> >> #Text >> 1 >> #NUM >> 3 >> #TSX NUM TX >> 1 1 0 >> >> #GRID >> 1 1 3 4 5 6 7 >> 3 4 3 5 6 6 7 >> 3 4 5 6 7 8 9 >> >> In the second call of the textscan function I wanted to read just the >> #GRID part. I want to know if we have another option to do that. >> Because I guess I can't use the same 'FID' from the same filename twice. >> >> Thanks for all!!
> Sorry, I already figure out how to solve my problem. > I don't know how to remove the topic, but if someone else need this > information, I'm using the textread function. Also a good choice.
You can't and even tho TMW can and does on occasion from their server/interface, since it's already disseminated on usenet there's no point in it...
The file _is_ formatted; otherwise you wouldn't be able to read it w/o a file viewer of some sort.
On the question; as long as you don't close the fid you got from fopen(), of course you can use it multiple times--that's the whole point of textscan() using fid's instead of passing the file name as does textread().
_BUT_, if you read the file and then tried to read it again using the 'headerlines' option w/o repositioning it, then obviously you'll have problems. That's what your description sounds like you did.
If your solution was to read first w/ textscan() and then again w/ textread(), that's pretty non-optimal.
textread(), while deprecated by TMW and not as fully flexible as textscan() does have some benefits that aren't available otherwise the primary of which is that it returns "ordinary" double arrays instead of cell arrays only a la textscan(). That can often be a nice advantage.
I keep harping on the desirability of continuing to fully support textread(). Whether the message is being received by TMW is hard to tell--there is essentially no feedback other than in whatever it is they choose to release on the next release, unfortunately.