필터 지우기
필터 지우기

textscan trouble: starting file position on re-read

조회 수: 1 (최근 30일)
David C
David C 2014년 6월 19일
편집: per isakson 2015년 5월 10일
I'm trying to read a data file of integers. The file is formatted as follows:
-112-999-999-999-555
-999-999
-777 0 0 0 0
0 20
-757 11 0 0 0
0 0
There are 3 blocks of 7 numbers each.
I tried
fid=fopen('filename.txt')
textscan(fid,'%4d',7)
And got the following as expected.
-112
-999
-999
-999
-555
-999
-999
But then I issue &nbsp textscan(fid,'%4d',7) &nbsp again. I would expect to get the second block this time, but instead I get:
2
-999
-999
-999
-555
-999
-999
It seems textscan started reading at the wrong place (not where it left off).
Any thoughts why it's doing this?
Thanks, David
  댓글 수: 5
Patrick
Patrick 2014년 10월 9일
I ran into this same issue with R2013b.

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

답변 (1개)

Image Analyst
Image Analyst 2014년 6월 20일
In your second call to textscan() your first argument is fww. What is that? Why are you not using fid like in the first call to textscan()????
  댓글 수: 9
Stephen23
Stephen23 2014년 10월 10일
편집: Stephen23 2014년 10월 10일
Tested with MATLAB R2012b. I downloaded your data file filename.txt, and ran the following code:
>> fid = fopen('filename.txt');
>> A(1) = textscan(fid,'%4d',7);
>> A(2) = textscan(fid,'%4d',7);
>> fclose(fid);
>> [A{:}]
ans =
-100 -106
-101 107
-102 108
-103 0
-555 0
-104 0
-105 20
This seems to give the outputs you want.
per isakson
per isakson 2015년 5월 10일
편집: per isakson 2015년 5월 10일
With 2014a
ans =
-100 0
-101 -101
-102 -102
-103 -103
-555 -555
-104 -104
-105 -105
was this ever reported?

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

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by