Call of textscan or strfind function takes long time for first time while running in loop [matlab 2020b on linux centos]
2 ビュー (過去 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
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
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
2 件のコメント
dpb
2021 年 7 月 14 日
I'm always forgetting that change in behavior, too...glad your rememberer is better, Walter! :)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Import and Export についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!