How to save current time in file name
Show older comments
Hi,
since MATLAB function datestr is now not recommended, I wanted to try saving with datetime. Unfortunately I keep getting errors.
What I used before:
filename = ['output ' datestr(now,'yyyy-mm-dd_HH_MM_SS') '.mat'];
save(filename,'-v7.3')
What I tried now:
filename = ['output ' string(datetime('now')) '.mat'];
save(filename,'-v7.3')
I wanted it in the 'yyyy-mm-dd_HH_MM_SS' format, but it's not that important.
The error I keep getting is:
"Error using save.
Argument must be a text scalar."
I also tried different things (what was shown in HELP) such as these
filename = ['output ' string(datetime('now'), 'yyyy-MM-dd hh:mm:ss') '.mat'];
filename = ['output %d .mat', string(datetime('now'), 'yyyy-MM-dd hh:mm:ss')];
or to separate it with commas, but nothing I come up with works. Can you guys help?
Accepted Answer
More Answers (0)
Categories
Find more on Calendar in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!