You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: of_mean_hilo_KGE.m
    path of file: ./repos/MARRMoT/MARRMoT/Functions/Objective functions
    
    the code of the file until where you have to start completion: function [val,c,idx,w] = of_mean_hilo_KGE(obs,sim,idx,w)
% of_mean_hilo_KGE Calculates the average Kling-Gupta Efficiency of the 
% normal and inverse of simulated streamflow (Gupta et al, 2009, 
% Pushpalatha et al, 2012).

% Copyright (C) 2019, 2021 Wouter J.M. Knoben, Luca Trotter

    
function [val,c,idx,w] = of_mean_hilo_KGE(obs,sim,idx,w)
% of_mean_hilo_KGE Calculates the average Kling-Gupta Efficiency of the 
% normal and inverse of simulated streamflow (Gupta et al, 2009, 
% Pushpalatha et al, 2012).

% Copyright (C) 2019, 2021 Wouter J.M. Knoben, Luca Trotter
% This file is part of the Modular Assessment of Rainfall-Runoff Models
% Toolbox (MARRMoT).
% MARRMoT is a free software (GNU GPL v3) and distributed WITHOUT ANY
% WARRANTY. See <https://www.gnu.org/licenses/> for details.

% In:
% obs       - time series of observations       [nx1]
% sim       - time series of simulations        [nx1]
% idx       - optional vector of indices to use for calculation, can be
%               logical vector [nx1] or numeric vector [mx1], with m <= n
% w         - optional weights of components    {[3x1] [3x1]} {high low}
                                            %or [3x1] high = low
%
% Out:
% val       - objective function value          [1x1]
% c         - components [r,alpha,beta]         {[3x1] [3x1]} {high low}
% idx       - indices used for the calculation
% w         - weights    [wr,wa,wb]             {[3x1] [3x1]} {high low}
%
% Gupta, H. V., Kling, H., Yilmaz, K. K., & Martinez, G. F. (2009). 
% Decomposition of the mean squared error and NSE performance criteria: 
% Implications for improving hydrological modelling. Journal of Hydrology, 
% 377(1–2), 80–91. https://doi.org/10.1016/j.jhydrol.2009.08.003
%
% Pushpalatha, R., Perrin, C., Moine, N. Le, & Andréassian, V. (2012). A 
% review of efficiency criteria suitable for evaluating low-flow 
% simulations. Journal of Hydrology, 420–421, 171–182. 
% https://doi.org/10.1016/j.jhydrol.2011.11.055

%% Check inputs and select timesteps
if nargin < 2
    error('Not enugh input arguments')    
end