Exportgraphics is not overwriting
59 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a set of figures that I'm saving using exportgraphics, after making some changes to the programm i get a new set of figures but exportgraphics is not overwriting it. I have been using this to export images for a long time and it used to overwrite, but since yesterday it isn't doing so. Any ideas about what may be causing this?
3 Kommentare
DGM
am 13 Jul. 2024 um 8:29
Bearbeitet: DGM
am 13 Jul. 2024 um 8:33
f2 = ""; % just for forum testing
filenameEN = fullfile(f2,"xyz.jpg");
x = 1:100;
y = 100:-1:1;
fig = gcf;
% i'm going to repeatedly plot and save the screenshot
for k = 1:3
plot(x,y)
fig.Units='inches';
fig.Position=[0,0,8,8.5];
exportgraphics(fig, filenameEN,'Resolution', 120);
imfinfo(filenameEN).FileModDate % check the timestamp
pause(3)
end
I'm not sure why the forum editor dumps the figure twice here, but all I'm looking for are the timestamps, which do change.
My point in testing this here on the forum isn't strictly demonstrative; it's simply that I run R2019b, which doesn't have exportgraphics(), so the forum is where I'd have to test it.
From my vantage point, I don't see a good reason why exportgraphics() wouldn't write the file, though I think there's probably an explanation that I simply can't see from where I'm at. For example, I've had scenarios where my file manager simply stopped updating the contents of the directory I was looking at. It might be worth trying to use imfinfo() as above to programmatically check the file for changes.
That said, I would hope that someone else can chime in with more insight on newer versions.
One last note which is completely unrelated to the main problem:
I strongly recommend using PNG for capturing line plots like this. JPG will produce a visually degraded copy and a larger file size than a PNG. Unless you need JPG for compatibility reasons, it's best avoided for simple synthetic images. Again, that shouldn't be affecting the file-overwriting issue at all. Just general advice.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Printing and Saving finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!