function [varData] = matchVars_MLH(fileList,indices,directory)

    varData = cell(length(fileList), 1);

    for i = 1:length(fileList)
        idx = indices{i};
        [path, filename, ext] = fileparts(fileList{i});

        h5_path = strrep(path, '/PBLH',directory);
        h5_file = strcat(filename,'.h5');
        full_path_h5 = strcat(h5_path,h5_file);                
        gps_time = h5read(full_path_h5,  '/ApplanixIMU/gps_time');

        %compute the average lidar MLH around the profile time
        range = 10;
        idx = indices{i};
        %var_cell = cell(length(idx),1);
        var_cell = [];
        for c = 1:length(idx)
            idx_prof = idx{c};
            if ~isempty(idx_prof)
                % find the middle of the profile
                num_indices = length(idx_prof);
                if num_indices == 1
                    idx_val = idx_prof;
                elseif mod(length(idx_prof),2) == 1
                    idx_mid = ceil(length(idx_prof)/2);
                    idx_val = idx_prof(idx_mid);
                else
                    idx_mid1 = length(idx_prof)/2;
                    idx_mid2 = length(idx_prof)/2 + 1;
                    idx_val = idx_prof(idx_mid1);
                    %idx_val = (idx_prof(idx_mid1) + idx_prof(idx_mid2)) /2;
                end
                i_start = idx_val - range;
                i_end = idx_val + range;
                if i_start < 1 || i_end > length(gps_time)
                    var_cell(c) = NaN;
                else
                    time_prof = gps_time(idx_val);
                    var_cell(c) = time_prof;
                end
            else
                var_cell(c) = NaN; %no profile to match to lidar 
            end

        end
        varData{i} = var_cell;













       
    end


end






