source: Roms_tools/air_sea/binave.m @ 2

Last change on this file since 2 was 1, checked in by cholod, 13 years ago

import Roms_Agrif

File size: 1.2 KB
Line 
1function 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
20if nargin < 2
21   error('Not enough input arguments.')
22end
23if abs(r-fix(r)) > eps
24   error('Bin size R must be a positive integer.')
25end
26if fix(r) == 1
27        bindat = data;
28        return
29end
30if r <= 0
31        error('Bin size R must be a positive integer.')
32end
33
34[N,M]=size(data);
35
36% compute bin averaged series
37l = length(data)/r;
38l = fix(l);
39bindat = mean(reshape(data(1:l*r),r,l));
40
41if length(data)>l*r,
42 bindat=[bindat,mean(data(l*r+1:end))];
43end;
44
45if N~=1
46  bindat=bindat';
47end
48
49
50
Note: See TracBrowser for help on using the repository browser.