MATLAB Answers

I am using saveas function of Matlab to save figures but sometimes it gives me "Error using print (line 82) PNG library failed: Could not open file.."

조회 수: 177(최근 30일)
Aditya
Aditya 2018년 8월 16일
편집: Ann 2021년 7월 22일
I am using saveas function of Matlab to save figures but sometimes my loop breaks gives me the above error, so I restart the loop and it starts working again, which makes me wanna think if there is any bug in the saveas function, because my code seems to be running when started again.
for m = 1:305
mkdir (Names{m});
folder = Names{m};
k = 1;
Limit = size(samples{m},2)
if(GenderList(m) == 1)
Temp = 'male';
else
Temp = 'female';
end
for i = 1:Limit
[coeffs,delta] = mfcc(samples{m}(:,i),fs);
f = figure('visible', 'off');
baseFileName = strcat(Names{m},'_',Temp,'_coeffs_', num2str(i,'%02d'),'.png');
fullFileName = fullfile(folder, baseFileName);
imagesc(coeffs);
saveas(f, fullFileName, 'png');
baseFileName2 = strcat(Names{m},'_',Temp,'_delta_', num2str(i,'%02d'),'.png');
fullFileName2 = fullfile(folder, baseFileName2);
imagesc(delta);
saveas(f, fullFileName2, 'png');
k = k+1;
clear coeffs;
clear delta;
i
end
clear k;
clear Temp;
end
  댓글 수: 1
Jan
Jan 2018년 8월 16일
This can happen if the file is existing, but opened already. Can you exclude this?
By the way, omit the useless clear commands. They waste time only here.

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

답변(1개)

Ann
Ann 2021년 7월 21일
편집: Ann 2021년 7월 22일
I recently experience this error too, when using
print(figurehandle, '-dpng', [path])
It seems to occur randomly; my function which repeatedly creates figures and saves them to a folder using above code will work a few times, then crash. Troubleshooting by putting 'keyboard' in the line before the crashing one, and running the print(...) command by Evaluate Selection, then often does NOT reproduce the error.
I now think that this has to do with the folder to which my function tries to print; this is a local directory that gets automatically synced by Dropbox. During syncing the permission may change briefly.

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by