Using Dates (if possible) as structure fields.
9 次查看(过去 30 天)
显示 更早的评论
I'd like to know if there's a way to use dates as struct fields. The data I want to store in the struct comes in a daily basis and I'd like to store it inside a struct. The thing is I cannot have field names such as "12/17/2017", nor "12_17_2017" because none of them begin with a letter and in the 1st case I have special characters such as "/" that are forbidden.
Is there a workaround you could suggest to save the data into a struct closely to the way I describe it?
Thanks for your time!
3 个评论
Walter Roberson
2017-12-19
Using datetime objects helps in those cases, as you can can simply set the Format property to the format you need for the purpose without having to do any explicit conversion of formats.
回答(2 个)
Walter Roberson
2017-12-18
See https://www.mathworks.com/help/matlab/ref/genvarname.html
Or prefix the date with a character and use strrep or regexprep to change the delimiters. Or use datestr to change the date format or change the Format property of a datetime object.
0 个评论
Peter Perkins
2017-12-19
It's quite possible that you could use a timetable, in which each row is labelled with a datetime. Hard to say without more info about what you are doing.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!