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

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';
print(gcf,header,'-dpng','-r300');

 Respuesta aceptada

Jon
Jon el 29 de Oct. de 2021
x = [1 2 3]
y = x.^2
plot(x,y)
exportgraphics(gcf,'/Volumes/Expansion/dispersion/myplot.jpg')

5 comentarios

Jon
Jon el 29 de Oct. de 2021
On my Windows 10 computer the slashes go the other way \Volumes\Expansion\...
Not sure if you are on another OS, or if you just made the slashes the other way. In anycase I guess MATAB doesn't really care which way they go.
I just typed them wrong
Jon
Jon el 29 de Oct. de 2021
We're you able to get exportgraphics to save your figure as you wanted?
No, I'm using an older version of matlab. How can I do it in 2019b?
Jon
Jon el 29 de Oct. de 2021
Editada: Jon el 29 de Oct. de 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)
print(name,'-dpng','-r300')
In the above I also built the filename programatically in case you wanted to do that

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Centro de ayuda y File Exchange.

Preguntada:

el 29 de Oct. de 2021

Editada:

Jon
el 29 de Oct. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by