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});

        txt_path = strrep(path, '/PBLH','/Archive/MLH/');
        txt_file = strcat(filename,'.txt');
        full_path_txt = strcat(txt_path,txt_file);
        try 
            data = readtable(full_path_txt, 'HeaderLines', 1);
            mixedlayer = data(:,23);
            mixedlayer = table2array(mixedlayer);
        catch exception 
            txt_file1 = strrep(txt_file, '.txt','_F1.txt');
            full_path_txt1 = strcat(txt_path,txt_file1);
            txt_file2 = strrep(txt_file, '.txt','_F2.txt');
            full_path_txt2 = strcat(txt_path,txt_file2);
            data1 = readtable(full_path_txt1,'HeaderLines', 1);
            data2 = readtable(full_path_txt2,'HeaderLines', 1);
            mlh1 = table2array(data1(:,23));
            mlh2 =table2array(data2(:,23));
            mixedlayer = [mlh1;mlh2];
        end

        %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;
                %disp(length(mixedlayer));
                if i_start < 1 || i_end > length(mixedlayer)
                    var_cell(c) = NaN; 
                else
                    mlh_range = mixedlayer(i_start:i_end);
                    mlh_mean = mean(mlh_range, 'omitnan');
                    var_cell(c) = mlh_mean;
                end
            else
                var_cell(c) = NaN; %no profile to match to lidar 
            end
            
        end
        varData{i} = var_cell; 

    end                
        
end






