How do I save a figure as a png to a different directory?

4 views (last 30 days)
I need help saving my figure to a different directory than the one I'm running my code in. The directory I want to save it to is /Volumes/Expansion/dispersion.
This is what I have so far. I'm not sure how to incorporate the directory I want to save the figure to.
header = 'title of figure on plot';

Accepted Answer

Jon on 29 Oct 2021
x = [1 2 3]
y = x.^2
Jon on 29 Oct 2021
Edited: Jon on 29 Oct 2021
If you just want to use the print command as you have started, you just have to append the path to the filename so:
filename = 'myfile'
name = fullfile('Volumes','Expansion','dispersion',filename)
In the above I also built the filename programatically in case you wanted to do that

Sign in to comment.

More Answers (0)


Find more on File Operations 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!

Translated by