exportgraphics does not save at specific location
Show older comments
I have a figure that I want save with exportgraphics(), but I get an error about the path.
>> str_save = '~/Documents/MATLAB/A/B/C/test_file_name.pdf';
>> isfolder('~/Documents/MATLAB/A/B/C/')
ans =
logical
1
>> exportgraphics(fig, str_save)
Error using exportgraphics
Problem while processing in an OutputHelper. ~/Documents/MATLAB/A/B/C/test_file_name.pdf (No such file or directory)
com.mathworks.hg.util.OutputHelperProcessingException: Problem while processing in an OutputHelper. ~/Documents/MATLAB/A/B/C/test_file_name.pdf (No such file or directory)
at com.mathworks.hg.util.HGVectorOutputHelper.open(HGVectorOutputHelper.java:76)
Caused by: com.mathworks.hg.print.OutputProcessingException: ~/Documents/MATLAB/A/B/C/test_file_name.pdf (No such file or directory)
at com.mathworks.hg.print.BaseVectorStrategy.open(BaseVectorStrategy.java:30)
at com.mathworks.hg.util.HGVectorOutputHelper.open(HGVectorOutputHelper.java:66)
If I save it to the current working directory
str_save = './test_file_name.pdf';
it works. When I save it with print() instead of exportgraphics() it also works.
Adding the output folders to the current path (via GUI or code) does not change the error.
Could this have to do with write access? But checking the rights with fileattrib() says I have write access (which should be the case since the folder is created in my script with 774 rights).
Accepted Answer
More Answers (1)
The folder is existing but Matlab cannot create a file in it. Then Matlab does not have write permissions in this folder.
fileattrib('~/Documents/MATLAB/A/B/C/')
Allow the current user to create files in this folder.
4 Comments
Felix Müller
on 29 Jun 2022
Is this successful:
str_save = '~/Documents/MATLAB/A/B/C/test_file_name.pdf';
[fid, msg] = fopen(str_save, 'w');
assert(fid > 0, '%s', msg)
Is this the real path name or is "A/B/C" an abbreviation of a name containing Unicode characters?
Felix Müller
on 29 Jun 2022
Felix Müller
on 1 Jul 2022
Categories
Find more on Environment and Settings 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!