-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomp_tspat_corr.m
83 lines (58 loc) · 1.46 KB
/
comp_tspat_corr.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
80
81
82
83
function R = comp_tspat_corr(fld1, fld2, mval)
n = length(fld1)
[r1, c1] = size(fld1{1});
[r2, c2] = size(fld2{1});
if r1 ~= r2 | c1 ~= c2
error('Input fields must have the same the same length')
end
% R = NaN(r1);
mn_1 = zeros(r1, c1);
mn_2 = zeros(r1, c1);
sig_1 = zeros(r1, c1);
sig_2 = zeros(r1, c1);
nom = zeros(r1, c1);
for k = 1:n
mn_1 = mn_1 + fld1{k};
mn_2 = mn_2 + fld2{k};
end
mn_1 = mn_1/n;
mn_2 = mn_2/n;
% keyboard
for k = 1:n
sig_1 = sig_1 + (fld1{k} - mn_1).^2;
sig_2 = sig_2 + (fld2{k} - mn_2).^2;
nom = nom + (fld1{k} - mn_1).*(fld2{k} - mn_2);
end
sig_1 = sqrt(sig_1);
sig_2 = sqrt(sig_2);
% nom = nom;
% keyboard
R = nom./(sig_1.*sig_2);
% tmp_1 = shiftdim(fld1_new(i,j,:));
% tmp_2 = shiftdim(fld2_new(i,j,:));
% mn_1 = mean(tmp_1);
% mn_2 = mean(tmp_2);
%
% sig_1 = std(tmp_1);
% sig_2 = std(tmp_2);
% if abs(sig_1) < 1e-5
% sig_1 = 1e-10;
% end
%
% if abs(sig_2) < 1e-5
% sig_2 = 1e-10;
% end
%
% if abs(mn_1) < 1e-5
% mn_1 = 1e-10;
% end
%
% if abs(mn_2) < 1e-5
% % mn_2 = 1e-10;
% % end
%
% R(i,j) = 1/n*((tmp_1 - mn_1)'*(tmp_2 - mn_2))/(sig_1*sig_2);
%
% end
% end
%