フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Strange error importing matrices in a loop

1 回表示 (過去 30 日間)
Jasper
Jasper 2015 年 11 月 1 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hello,
im importing 100 matrices in a loop and performing some calculations on every single one matrix before exporting and concatenating end results. For some reason, matrix #94 is not the expected 900x6 size but just the single value '48000'. Do you know what causes this? The same script (see partially below) has been fully working in the past, but not anymore. I have tried renaming and/or remaking that particular matrix from scratch, without success. If I isolate the matrix and try to import it outside a loop, that works... so it seems to only be failing in the loop.
Thanks in advance!
for i=1:100 % loop over files
if i < 10 % identify filenames per iteration
g=num2str(i);
num = strcat({'00'},{g});
stgnum=char(num);
elseif i < 100
g=num2str(i);
num = strcat({'0'},{g});
stgnum=char(num);
else
g=num2str(i);
num = strcat({g});
stgnum=char(num);
end
tracks_file = ['AA','#',stgnum,'.mat'];
dir_tracks = ['F:\any directory',tracks_file];
% data is imported below, one sequence each iteration of the main loop
A = importdata(dir_tracks);
end
  3 件のコメント
Jasper
Jasper 2015 年 11 月 2 日
Hi Geoff,
as for all the other iterations, the same directory is still being assigned (the matrices are input from the same dir), so that is not the problem. Thanks for your reply, any other ideas?
Jasper
Stephen23
Stephen23 2015 年 11 月 2 日
Use sprintf instead of that awkward concatenation and if-|else| operation, and use fullfile to generate the full path string:
myPath = 'F:\any directory';
myForm = 'AA#%03d.mat';
for k = 1:100
myName = sprintf(myForm,k);
myFull = fullfile(myPath,myName);
%A = importdata(myFull);
end

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 11 月 2 日
編集済み: Stephen23 2015 年 11 月 2 日
Given that set of conditions, my suspicion would be that importdata() is leaking open files -- that is, failing to close files after it opens them. As an experiment, right after your importdata() line, add
close('all');

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by