error using savefig and saveas

58 views (last 30 days)
Valeria Leto
Valeria Leto on 30 Oct 2021
Commented: Valeria Leto on 1 Nov 2021
Hi guys! I get this error message but I don't understand why. I saw other people asked about it but I have no clue why it happens. Maybe because my fig is too big? I tried also with saveas(gcf, 'mosaico.fig') but it doesn't work.Thanks
Error using save
Error closing file C:\Users\utente\Desktop\TESI\CODICI\missione
GRID\gestire_sovrapposizioni\automatizzare\mosaico.fig.
The file may be corrupt.
Error in matlab.graphics.internal.figfile.FigFile/write (line 32)
save(obj.Path, obj.MatVersion, '-struct', 'SaveVars');
Error in savefig (line 83)
FF.write();
Error in f_massimi (line 53)
savefig('mosaico.fig')

Accepted Answer

Dave B
Dave B on 30 Oct 2021
I'm not sure why you're seeing this error, if it's due to the file being too large there are a couple of things that you can try:
1. Try appending the 'compact' flag to savefig:
This will prevent MATLAB from storing a compatibility layer which adds support for loading your figure in releases older than R2014b. The compatibility layer is quite large, so this makes a dramatic difference to file size, and also would work around any issues that are specific to this set of data.
savefig('mosaico.fig','compact')
2. Change your default mat file format, which can be done in the preferences window (under general). Setting this to version 7.3 or later will allow larger files.
However, the error reports a problem closing the file, which seems surprising for a large file. Perhaps something on the OS is using the file and MATLAB can't get write access? These sometimes show up for network drives, but it looks like you're targeting your desktop folder so I'd be surprised if there's an issue. But it still seems worth trying another a location?
  4 Comments
Dave B
Dave B on 1 Nov 2021
Absolutely, unless you're planning on loading the fig files in a really old release I recommend it.

Sign in to comment.

More Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!