Using a String Variable to Name a Diary File
13 次查看(过去 30 天)
显示 更早的评论
I would like to be able to create a Log file with a different name whenever I want to. I would like to do this using the current time.
DiaryName = strcat('Paper_',datestr(now,'yyyy_mm-dd_HH:MM:SS')); diary(DiaryName.log)
However, I get an error when this happens:
"Attempt to reference field of non-structure array."
I also tried making the '.log' part of DiaryName:
DiaryName = strcat('Paper_',datestr(now,'yyyy_mm-dd_HH:MM:SS'),'.log') diary(DiaryName)
I tried also diary('DiaryName'), but this created a file called 'DiaryName' instead of giving it the name with the time stamp that I wanted to give it.
Any thoughts on what I can do?
In addition, I have directed Matlab to change paths to the directory where my .m files are (the Main directory). I have created a folder called "Diary" within the Main folder. Is it possible to create a Macros in Matlab to avoid having to specify the whole path for the folder Diary? Specifically, it would be great if I could make a Macro called DiaryPath, and the do diary($DiaryPath\'DiaryName'.log) to save the diary there?
Thanks a lot!
0 个评论
回答(2 个)
Jan
2014-10-12
编辑:Jan
2014-10-12
Is it clear, why "DiaryName.log" must fail? The code means, that the field "log" of the struct "DiaryName" is wanted, but DiaryName is a string.
What is the problem with this commands:
DiaryName = strcat('Paper_', datestr(now,'yyyy_mm-dd_HH:MM:SS'), '.log');
diary(DiaryName)
Under Windows the ':' is not allowed in path names.
Instead of a macro let "DiaryPath" be a function, which replies the wanted folder:
function P = DiaryPath
P = 'C:\YourFolder\';
You have tried
diary(DiaryName)
and
diary('DiaryName')
This is pure guessing. Better read the Getting Started chapters of the documentation an rely on educated guessing only.
Seo Woo Park
2019-10-18
diary(strcat('Paper_',datestr(now,'yyyy_mm-dd_HH:MM:SS')))
might be work
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!