-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcentral_diff.m
83 lines (60 loc) · 2.65 KB
/
central_diff.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function ddt = cdiffcell(inpt, varargin);
% The function computes the first derivative of a given input dataset inpt
% according to the method of central differences. For the first (last)
% field, the derivative is computed according to forward (backward)
% differences.
%--------------------------------------------------------------------------
% Input: inpt {m x n} Cell array which contains the input
% fields.
% clms [1 x 3] column indices of the input containing
% month, year and the corresponding field
% [1 x 1] column index of the input fields
% miss [1 x 1] value of undefined elements in the
% input fields
% id_map [i x j] Map which defines the different areas
% area_id [1 x k] Vector (or scalar) which contains the
% ids of the desired areas
%
% Output: otpt [m x k] matrix containing the area-weighted
% means
%--------------------------------------------------------------------------
% Author: Christof Lorenz
% Date: July 2011
%--------------------------------------------------------------------------
% Uses: area_wghts.m
%--------------------------------------------------------------------------
% Checking input arguments and setting default values
pp = inputParser;
pp.addRequired('inpt', @(x)iscell(x)); % Input dataset (cell)
pp.addOptional('clms', [4 5 9], @(x) isnumeric(x)); % Columns of m/y/flds
pp.addOptional('time', [0 0 0 0], @(x) isnumeric(x)); % start and end time
pp.parse(inpt, varargin{:})
clms = pp.Results.clms;
time = pp.Results.time;
keyboard
if size(clms) == [1 1] % No time information is available
indx_c = (1:length(inpt))';
indx_b = [1; indx_c(1:end-1)];
indx_f = [indx_c(2:end); indx_c(end)];
div = [1; ones(length(indx_c)-2,1)*2; 1];
else
mnth = cell2mat(inpt(:, clms(1)));
yr = cell2mat(inpt(:, clms(2)));
flds = inpt(:,clms(3));
sind = find((mnth) == time(1) & yr == time(2))
eind = find((mnth) == time(3) & yr == time(4));
end
keyboard
fields = inpt(sind:eind, clms);
n = length(fields);
for i = 1:n
ddt{i,1} = fields{i,1};
ddt{i,2} = fields{i,2};
if i == 1
ddt{i,3} = fields{i+1,3} - fields{i,3};
elseif i == n
ddt{i,3} = fields{i,3} - fields{i-1,3};
else
ddt{i,3} = 1/2*(fields{i+1,3} - fields{i-1,3});
end
end