How to save a figure in a different directory and with a dynamic name using export_fig?

5 views (last 30 days)
Hello! I am using export_fig to save the plots I am producing with matlab. What I want to do is:
  1. Save the figures in a different directory than the one I am working.
  2. Give a dynamic name to the saved figure according to the file that the program is reading every time.
  3. Use the command -transparent to remove the grey area around the figure.
My code is this:
baseFileName = sprintf('mass_conc_%s',sprintf('%s',char(cellstr(date.date(1)))));
saveas(gcf,baseFileName,'pdf')
export_fig baseFileName -transparent
This code is not saving the .png file (produced with export_fig) with the same name as the pdf file and I cannot specify another directory for saving it.
Thank you in advance for your help! Dimitra

Answers (1)

Thorsten
Thorsten on 19 Jul 2016
Some hints, since it appears to be homework:
help fileparts % separate path, name and extension
help fullfile % to generate a new full filename
Use the functional syntax of print and export_fig, i.e., use parentheses (...)
export_fig(newfilename, 'transparent') % not sure if this is the right syntax

Community Treasure Hunt

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

Start Hunting!