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: icatb_calculate_eventAvg.m
    path of file: ./repos/gift/GroupICAT/icatb/icatb_helper_functions
    
    the code of the file until where you have to start completion: function eventAvg = icatb_calculate_eventAvg(tempTC, interpFactor, TR, windowSize, selectedOnset)
% calculates event average based on the onset, window size, interpolation
% factor
%
% Inputs:
% 1. tempTC - Time course
% 2. interpFactor - Interpolation factor
% 3. TR 
% 4. windowSize (sec)
% 5. selectedOnset - vector of onsets
%
% Output:
% eventAvg - event average

% Original Interpolation factor
origInterpFactor = interpFactor;

% Interpolation factor
interpFactor = ceil(origInterpFactor*TR);

    
function eventAvg = icatb_calculate_eventAvg(tempTC, interpFactor, TR, windowSize, selectedOnset)
% calculates event average based on the onset, window size, interpolation
% factor
%
% Inputs:
% 1. tempTC - Time course
% 2. interpFactor - Interpolation factor
% 3. TR 
% 4. windowSize (sec)
% 5. selectedOnset - vector of onsets
%
% Output:
% eventAvg - event average

% Original Interpolation factor
origInterpFactor = interpFactor;

% Interpolation factor
interpFactor = ceil(origInterpFactor*TR);

% Interpolated ICA
interpICA = icatb_interp(tempTC, interpFactor);

eventAvg = zeros(windowSize*origInterpFactor, 1); % initialise event average

%% Event Related Average
for ons = 1:length(selectedOnset)
    if selectedOnset(ons)*interpFactor == 0
        startOnset = 1;
    else
        startOnset = selectedOnset(ons)*interpFactor; % start onset
    end