Unable to exportgraphics or saveas: The value of 'destination' is invalid.

Hello matlab community,
I am trying to save my figures both in fig and png format. I was using these commands before without any problem but I started to get these errors:
Here is an example script I used to try:
a=[1:10]
b=[11:20]
plot(a,b)
saveas(gcf,'ab.fig')
exportgraphics(gcf,'ab.png','Resolution',600)
Saveas error:
Error using save
Unable to write file ab.fig: No such file or directory.
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 saveasfig (line 6)
savefig(h, name);
Error in saveas (line 153)
feval( ['saveas' format], h, name )
Error in untitled2 (line 4)
saveas(gcf,'ab.fig')
Exportgraphics error:
Error using exportgraphics
The value of 'destination' is invalid. Unable to create output file 'ab.png', No such file or
directory.
Previously I had problem using xline and I was using 'restoredefaultpath rehash toolboxcache' to fix it.
Would it be connected to each other somehow? How can I fix this problem?
Thank you for your time!

8 Comments

savefig(gcf,'ab.fig')
Try using savefig
if I try
savefig(gcf,'ab.fig')
I receive the below error:
Error using save
Unable to write file ab.fig: No such file or directory.
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 untitled3 (line 4)
savefig(gcf,'ab.fig')
What is the current directory? Do you have OS permission to write in that location?
Previously I had problem using xline and I was using 'restoredefaultpath rehash toolboxcache' to fix it.
Try this again, It may be the reason, as i dont get any errors with both commands when i run it online. Which version are you using ?
Hello,
My directory is as in the below and I used to save figures to that directory before without any problem. Maybe it is a naive question but how can I check my permissons ;?
I checked directory with 'cd' and 'pwd' but I do not what I am supposed to see about permission.
/Volumes/INTENSO 1/Field Data/FD_08.2019-07.2020/Z_DO/Met_2019_2020/Resp01
I have found this question about the related problem but I do not want to change any setting without knowing what it is since I am not very good at Matlab.
Edit for the link:
https://de.mathworks.com/matlabcentral/answers/843430-unable-to-write-file-permission-denied
Hello @VBBV and @Stephen23,
Somehow the problem is solved.
I tried 'restoredefaultpath rehash toolboxcache' again and it is working again.
I am using R2022b and recently I have these kind of troubles time to time. They are fixed either with restarting matlab or using the above command. But I do not know the source of the problem.
Thank you for your support.

Sign in to comment.

Answers (0)

Categories

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

Products

Release

R2022b

Asked:

on 11 Apr 2023

Moved:

on 11 Apr 2023

Community Treasure Hunt

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

Start Hunting!