-
Notifications
You must be signed in to change notification settings - Fork 1
/
computeKGE.m
29 lines (21 loc) · 972 Bytes
/
computeKGE.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
function kge = computeKGE(simulated, observed)
% Flatten the arrays to ensure they are treated as 1D vectors
simulated = simulated(:);
simulated = simulated(~isnan(simulated));
observed = observed(:);
observed = observed(~isnan(observed));
% Compute the mean of observed and simulated values
meanObserved = mean(observed,'omitnan');
meanSimulated = mean(simulated,'omitnan');
% Compute the standard deviation of observed and simulated values
stdObserved = std(observed,'omitnan');
stdSimulated = std(simulated,'omitnan');
% Compute the correlation coefficient
correlation = corr(simulated, observed);
% Compute the bias ratio
bias = meanSimulated / meanObserved;
% Compute the variability ratio
variability = (stdSimulated / meanSimulated) / (stdObserved / meanObserved);
% Compute the KGE
kge = 1 - sqrt((correlation - 1)^2 + (bias - 1)^2 + (variability - 1)^2);
end