I am creating a plot in the following manner:
>> X = [1 2 3 4 5];
>> plot(X', linewidth = 2)
Now, I want to save the plot in a pdf file:
>> exportgraphics(gca, 'Test.pdf')
This is the error that MATLAB spits out:
>> Error using exportgraphics. The value of 'destination' is invalid. Unable to create output file 'EdgeWeightEstimation.pdf', Permission
denied.
I would very much appreciate if anyone could point out what I am doing wrong and how I could corect it. Thank you.
- Kamal

1 个评论

Could you confirm that your command requested Test.pdf but that the error message refers to a completely different file name?

请先登录,再进行评论。

 采纳的回答

dpb
dpb 2022-6-25
编辑:dpb 2022-6-25
This isn't a MATLAB syntax error; it's indicating that your default working directory (the location given by cd at command line prompt) is one for which you do not have write permission. This is set in the OS permissions.
Change your target file name to include a fully-qualified file name including the directory location that is one to which you have write permissions (or change your working location to one instead is probably the more satisfactory solution longer term).
In general, you should have your starting location for MATLAB leave you in a working directory that is yours and writeable and not one of the MATLAB installation folders that are write protected.
Show us what
cd
returns...

4 个评论

Thank yo so much. You are right, the working directory turned out to be a cloud storage directory because the m-file I was using was in there. When I changed the working directory, the exportgraphic command worked.
Is there a way I could change the default working directory so that it is the working directory every time I work in MATLAB?
Thanks again.
Yes, and I recommend to do so...my personal preference for general day-to-day use is to use a specific MATLAB working folder so that all non-project-specific ML-related stuff is there...I also create a custom Utilities folder that is early in the MATLABPATH search order that holds a collection of generally useful m-file functions that may be used no matter what project am working on rather than duplicating them.
To set the startup location, go to the "General" tab in Preferences (under "Environment" section) and set it there to your working directory of choice.
Just for example (set yours to suit your working habits and local setup), my MATLABPATH begins as
C:\Users\Duane\Documents\MATLAB\Work
C:\Users\Duane\Documents\MATLAB\Utilities
C:\Users\Duane\Documents\MATLAB\MSWordUtils
C:\Users\Duane\AppData\Local\Temp\Editor_alrfc
C:\ML_R2020b\toolbox\matlab\capabilities
C:\ML_R2020b\toolbox\matlab\datafun
C:\ML_R2020b\toolbox\matlab\datatypes
...
which illustrates my initial working directory is first (and the one set for default startup), then the Utilities, then begins the MATLAB-generated list created during installation after those.
Without setting the preference, MATLAB starts in a different location depending upon how you invoke it which I always found to be most annoying. In your case, if you happened to start by double-clicking that m-file icon, it dynamically cd's to the location of the file which then caused the issue you had because it did something behind your back you weren't expecting.
Thank you so much for this valuable insight. Try as I might, I couldn't locate this piece of information elsewhere.
-- K
Yeah, while the doc is extensive, it isn't always as intuitive about where the more general stuff is and the lookup tools are built entirely around functions, not subjects.
If you just open the doc for MATLAB, there's a "Getting Started" section and this stuff is under "Environment and Settings" under it...
The link online doc is <matlab/startup-and-shutdown> which is a few levels down, but to TMW's credit does go into excruciating detail. It just takes digging to get there...

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Startup and Shutdown 的更多信息

产品

版本

R2022a

标签

Community Treasure Hunt

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

Start Hunting!

Translated by