Using a String Variable to Name a Diary File
14 ビュー (過去 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!