Clear Filters
Clear Filters

How to make filename that message + date&time using [imwrite function].

4 views (last 30 days)
The MATLAB code is {imwrite(red, datestr(now,'yyyy-mm-dd HH-MM-SS-FFF'),'png');}
I want to make file name "test_yyyy-mm-dd HH-MM-SS-FFF".png
Please, Let me know the method.
Thanks.

Accepted Answer

Kodavati Mahendra
Kodavati Mahendra on 5 Jun 2018
Edited: Kodavati Mahendra on 5 Jun 2018
filename = strcat(datestr(now,'yyyy-mm-dd HH-MM-SS-FFF'),'.png');
imwrite(red, filename);
Solved? Problem was with the syntax for imwrite :-)
Edit 1:
filename = strcat('Test_',datestr(now,'yyyy-mm-dd HH-MM-SS-FFF'),'.png');
imwrite(red, filename);
Now?
  3 Comments
Stephen23
Stephen23 on 5 Jun 2018
Edited: Stephen23 on 5 Jun 2018
@Junwon Park: using sprintf is often clearer than concatenating strings:
filename = sprintf('Test_%s.png',datestr(now,'yyyy-mm-dd HH-MM-SS-FFF'));

Sign in to comment.

More Answers (1)

Junwon Park
Junwon Park on 5 Jun 2018
Thank you so much. It's solved. :)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!