Reputation: 9170
Data
Financial Time Series Object (FINTS) with the following columns:
Date Time Number
I have data for every hour for every single day for 2 years.
Problem
I want to have the average for every hour for the past year. In other words, I want to have the time column with all 24 hours in a day and the corresponding number should be an average of all the past days at that same hour.
What I tried
I've tried looking at the perav, tsmovavg function and accumarray function. Any other ideas? I am new to Matlab so I don't even know how to loop over this time series data. There must be some sort of way to do this though considering the fact it is a time series object using time series specific functions.
Edit: I'd like to leave it in a time series ideally.
Upvotes: 1
Views: 114
Reputation: 168
Assuming your data has been stored in a Matrix F
, "Date" is year and "Time" is hour, you can use this for
loop to print average of the same time during different days of particular year y
:
for t=unique(F(:,2))
mean(F(F(:,2)==t & F(:,1)==y) ,3)
end
Explanation:
By using unique
you can retrieve different values of "Time". Two conditions inside the mean
make sure mean of the same "Time" in a particular year.
Upvotes: 1