Effacer les filtres
Effacer les filtres

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

4 vues (au cours des 30 derniers jours)
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 commentaire
dpb
dpb le 14 Juil 2021
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.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 14 Juil 2021
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 commentaires
dpb
dpb le 14 Juil 2021
I'm always forgetting that change in behavior, too...glad your rememberer is better, Walter! :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Import and Export dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by