how to modify a structure?
显示 更早的评论
Hello. I initialize (instantiate) a structure like this:
YourStruct = struct(...
'Date', {cell(2208,1)}, ...
'Hour', {zeros(2208,1)}, ...
'DryBulb', {zeros(2208,1)}, ...
'DewPnt', {zeros(2208,1)}, ...
'SYSLoad', {zeros(2208,1)}, ...
'NumDate', {zeros(2208,1)});
'Date' has 92 days, and 'Hour' has 24 hours, from 1 to 24. How can I express 'Date' and 'Hour' in serial date numbers and how do I present these serial date numbers in 'NumDate'? Thank you.
7 个评论
Image Analyst
2012-9-16
Please format properly (as Code).
UPT
2012-9-16
UPT
2012-9-16
Walter Roberson
2012-9-16
Please go back and edit your original posting to mark-up the code there.
Note: there is no "i" in my username.
UPT
2012-9-16
编辑:Oleg Komarov
2012-9-16
Walter Roberson
2012-9-16
Blank line before and after the code. Indent the code.
回答(1 个)
Walter Roberson
2012-9-16
NumDate = Data.Date + (Data.Hour - 1) / 24;
5 个评论
Walter Roberson
2012-9-16
Wait -- what exactly does the Date cell contain?
UPT
2012-9-16
Walter Roberson
2012-9-16
As strings? If so then use datenum() to convert them to serial date numbers and add (Hour-1)/24
UPT
2012-9-17
Walter Roberson
2012-9-17
Your Hour field is the same length as your Date field, which suggests you want exactly 1 hour conversion for each Date converted, rather than wanting to create 24 hour conversions for each Date converted.
data.NumDate = datenum(Data.Date) + (Data.Hour - 1) / 24;
except that you might need to add an additional parameter to datenum() in order to indicate the date format.
类别
在 帮助中心 和 File Exchange 中查找有关 Time Series Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!