Line | |
---|
1 | function bindat = binave(data,r)
|
---|
2 | % BINAVE: averages vector data in bins of length r.
|
---|
3 | % bindat=BINAVE(data,r) computes an average vector of the vector
|
---|
4 | % data in bins of length r. The last bin may be the average of
|
---|
5 | % less than r elements. Useful for computing daily average time
|
---|
6 | % series (with r=24 for hourly data).
|
---|
7 | %
|
---|
8 | % INPUT: data - data vector
|
---|
9 | % r - number of elements in bin to be averaged
|
---|
10 | %
|
---|
11 | % OUTPUT: bindat - bin-averaged vector
|
---|
12 |
|
---|
13 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
14 | % 3/8/97: version 1.0
|
---|
15 | % 9/19/98: version 1.1 (vectorized by RP)
|
---|
16 | % 8/5/99: version 2.0
|
---|
17 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
18 |
|
---|
19 | % check input
|
---|
20 | if nargin < 2
|
---|
21 | error('Not enough input arguments.')
|
---|
22 | end
|
---|
23 | if abs(r-fix(r)) > eps
|
---|
24 | error('Bin size R must be a positive integer.')
|
---|
25 | end
|
---|
26 | if fix(r) == 1
|
---|
27 | bindat = data;
|
---|
28 | return
|
---|
29 | end
|
---|
30 | if r <= 0
|
---|
31 | error('Bin size R must be a positive integer.')
|
---|
32 | end
|
---|
33 |
|
---|
34 | [N,M]=size(data);
|
---|
35 |
|
---|
36 | % compute bin averaged series
|
---|
37 | l = length(data)/r;
|
---|
38 | l = fix(l);
|
---|
39 | bindat = mean(reshape(data(1:l*r),r,l));
|
---|
40 |
|
---|
41 | if length(data)>l*r,
|
---|
42 | bindat=[bindat,mean(data(l*r+1:end))];
|
---|
43 | end;
|
---|
44 |
|
---|
45 | if N~=1
|
---|
46 | bindat=bindat';
|
---|
47 | end
|
---|
48 |
|
---|
49 |
|
---|
50 |
|
---|
Note: See
TracBrowser
for help on using the repository browser.