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.

 Respuesta aceptada

Image Analyst
Image Analyst el 28 de En. de 2012

0 votos

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.

Más respuestas (1)

Honglei Chen
Honglei Chen el 27 de En. de 2012

0 votos

You can use imwrite and date
doc imwrite
doc date

3 comentarios

Syed Abbas
Syed Abbas el 27 de En. de 2012
i am not sure how i can use that. But to simplify things, i want to do something as the following:
dte = datestr(now)
saveas('C:\docs\dte') where dte is replaced by todays date.
Walter Roberson
Walter Roberson el 27 de En. de 2012
today = date();
thisfile = ['C:\docs\' today];
saveas(thisfile)
Syed Abbas
Syed Abbas el 31 de En. de 2012
Thanks!

Iniciar sesión para comentar.

Categorías

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by