-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd_correlation.m
61 lines (52 loc) · 2.21 KB
/
d_correlation.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
function correl_matrix = d_correlation(data, no_detect,full_data,d)
%D_CORRELATION 此处显示有关此函数的摘要
% purpose: calculate the correlation of d-closest data point to all data
% cells that are included in this study
% Currently for CCWM.
% parameter: data - original data containing missing value
% no_detect - indicate which data cell is not included in the
% study.
% full_data - indexes of data entry without missing value.
% (in terms of date)
% d - d-closest data used in IDVM
% output: correl_matrix - 16*17*d*3 matrix for each cell
% (correlation, longitude index, latitude
% index)
%each entry stores - correlation, longitude index, latitude index.
[lo, la, dts] = size(data);
correl_matrix = zeros(lo, la, d+1, 3);
for ci=1:lo
for cj=1:la
if (no_detect(ci, cj))
continue;
end
correls = [];
is = [];
js = [];
for i=1:lo
for j=1:la
if (no_detect(i, j)==0)
correl = corrcoef(data(ci, cj, full_data), data(i, j, full_data));
correl = correl(1,2);
correls = [correls, correl];
is = [is, i];
js = [js, j];
[B,I] = sort(correls, 'descend');
is = is(I);
js = js(I);
if (length(correls)>(d+1))
correls = B(1:(d+1));
is = is(1:(d+1));
js = js(1:(d+1));
end
end
end
end
for p=1:(d+1)
correl_matrix(ci, cj, p, 1) = correls(p);
correl_matrix(ci, cj, p, 2) = is(p);
correl_matrix(ci, cj, p, 3) = js(p);
end
end
end
end