Time series, resample, axes, datetime

1 次查看(过去 30 天)
Anyone to lead me in the right direction please?
I have energy consumption data of more than 3 years for every two seconds (43200 per day). Different households. How do I set the x axis into 24hrs (00:00 - 23:59) and plot each day data on one graph?
I have two variables (power and time). Files are saved as dates and have 43200 data each for power and time. I also have two variables called start_date and end_date. I would like to select any range of dates and get those dates data plotted in one graph. Later I will need to resample the time since, color each day plot, etc. I have attached a figure to explain more/less what im trying to do.
I highly appreciate your assistance in this. Thanks

采纳的回答

dpb
dpb 2015-2-24
编辑:dpb 2015-2-24
Use date numbers...example for an axes...
>> dn=datenum(2000,1,1,0,0,[0:2:86400-1].'); % a day at 2-sec interval
>> t=dn-dn(1); % make 0-based
>> p=normpdf(t,0.5,.1); % some data to plot...
>> plot(t,p)
>> set(gca,'xtick',[0:2:24]/24) % set tick marks at 2-hr
>> datetick('x','HH:MM','keeplimits','keepticks') % format the time axis
>> set(gca,'xminortick','on') % minor ticks for odd hrs
>>
For the selection, convert the requested time ranges into date numbers, too, and use the logical operations to select between, inclusive or not, etc., ...
NB: When generating series of date numbers, always use integer multiples of the smaller time granule such as seconds above rather than dividing out the fraction of an hour or day and using floating point deltas. The latter will end up with floating point comparisons that do NOT compare owing to that rounding whereas the rounding will be consistent inside datenum and friends if use the integer deltas. As can be seen in the above example, the functions are "smart enough" to know how to wrap times when building the vector.
In your case, you'll be reading a time vector, presumably as string; simply convert it or ignore it and just build the time history as shown.
The example does not use the newer timeseries class; I don't have it in the version installed here. If choose to use it, some of the machinations are a little different but the ideas are the same. One thing you do have to be aware of is that there's a whole different set of formatting abbreviations between the two.
  15 个评论
ccs
ccs 2015-3-2
OK, my misunderstanding; I thought your intent was to plot the various days on the single plot as multiple lines overlaid to see the typical daily pattern, not as a single time series.
Wow...I think I have panicked already or english is also a problem. That is exactly what I intend to do. I don't want to concatenate them
dpb
dpb 2015-3-2
Well, in that case we're back to the previous of "every day's the same" excepting for the base time. So, the selection is only on the data files, basically, and there the simple way would be to process all the dates once building a date number time series that spans the overall time of the available data and use that to look up the actual data.
We're heading out; I think if you just take the basic pieces we've talked about and start will get there..

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by