Saving figure

2 Ansichten (letzte 30 Tage)
Syed Abbas
Syed Abbas am 27 Jan. 2012
Hi,
I have an m file which generates a figure. I run this m file daily. But each day, I have to name and manually save the figure. Is there a way to automatically save the figure with todays date as the file name? I know how to automatically save the figure but I am not sure how to use todays date as the file name. Thanks.

Akzeptierte Antwort

Image Analyst
Image Analyst am 28 Jan. 2012
Use datestr() but be sure to change the colons to a valid character!!!
Try this:
% Get date-time string.
baseFileName = datestr(now)
% Colons aren't allowed in filenames.
% Replace them with underlines
baseFileName = strrep(baseFileName, ':', '_');
% Add extension.
baseFileName = [baseFileName '.png']
Then call export_fig() as usual.
  1 Kommentar
Syed Abbas
Syed Abbas am 31 Jan. 2012
Thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Honglei Chen
Honglei Chen am 27 Jan. 2012
You can use imwrite and date
doc imwrite
doc date
  3 Kommentare
Walter Roberson
Walter Roberson am 27 Jan. 2012
today = date();
thisfile = ['C:\docs\' today];
saveas(thisfile)
Syed Abbas
Syed Abbas am 31 Jan. 2012
Thanks!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by