-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreduce_intrahour_freq.m
37 lines (33 loc) · 1.24 KB
/
reduce_intrahour_freq.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function [ out_series ] = reduce_intrahour_freq( in_series, in_num_obs, out_num_obs, dateColumns )
%REDUCE_INTRAHOUR_FREQ Function for reducing the number of observations per
%hour of the input series.
% INPUT:
% in_series: Input series with n_daysX24Xin_num_obs rows and as many
% columns as variables.
% in_num_obs: Number of observations per hour of the input series.
% out_num_obs: Number of observations per hour of the output series.
% dateColumns: Number of columns corresponding to the date.
%
% OUTPUT:
% out_series: Series with the reduced frequency
%
% - F. Mendoza (June 2017) Update
n_vars = size(in_series,2);
if in_num_obs>out_num_obs
if mod(in_num_obs,out_num_obs)==0
n_obs = in_num_obs/out_num_obs;
else
warning('The original number of observations divided by the new one must be an integer.');
return
end
else
warning('The new number of observations per hour is greater than the original number.');
return
end
out_length = size(in_series,1)/n_obs;
out_series = NaN(out_length,n_vars);
for i = 0:out_length-1
out_series(i+1,1:dateColumns) = in_series(i*n_obs+1,1:dateColumns);
out_series(i+1,dateColumns+1:end) = mean(in_series(i*n_obs+1:(i+1)*n_obs,dateColumns+1:end));
end
end