Call of textscan or strfind function takes long time for first time while running in loop [matlab 2020b on linux centos]

조회 수: 1 (최근 30일)
We are trying to read a file which has repeatedly 9 rows of text followed by 200000 particle trajectories. A piece of code, enough to produce the problem is:
fname = abc.txt;
fid = fopen(fname,'r');
for ii = 1:20
InputText=textscan(fid,'%s',9,'delimiter','\n');
ii
pp = InputText{1};
Nrows = pp{4}
aa =textscan(fid,'%d %d %f %f %f %f', ... % Read data block
'delimiter',',');
end
apparently, to print ii = 1, it takes 10 seconds while rest all calls in loop finish in 1-2 seconds. It clearly indicates that trouble is on first call of textscan and not with subsequent calls.
The same issue is with strfind function if i put in loop.
I checked on matlab and the answers suggest either license issue or graphics issue. I ran matlab with no-desktop and still got the same issue. I checked it with Nvidia and opengl software choice and issue persists.
Kindly help resolving.
  댓글 수: 1
dpb
dpb 2021년 7월 14일
InputText=textscan(fid,'%s',9,'delimiter','\n');
ii
pp = InputText{1};
Nrows = pp{4}
looks peculiar -- you read as char() data but then use the content as numeric without a conversion operation.

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

채택된 답변

Walter Roberson
Walter Roberson 2021년 7월 14일
Specify the file encoding when you do the fopen(), or else it will scan the entire file checking to see if any utf8 is present

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by