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

        if contains(path,'CPEX_CV')
            h5_path = strrep(path, '/PBLH',directory);
            h5_file = strcat(filename,'.h5');
            full_path_h5 = strcat(h5_path,h5_file);                
            mlh_h5 = h5read(full_path_h5,  '/MixedLayerHeight');
            %compute average MLH around dropsonde time
            range = 10;
            means = NaN(1, length(idx));
            for j = 1:length(idx)
                i_start = idx(j) - range;
                i_end = idx(j) + range;

                if i_start < 1 || i_end > length(mlh_h5)
                    continue;
                else
                    mlh_range = mlh_h5(i_start:i_end);
                    mlh_mean = mean(mlh_range, 'omitnan');
                end

                means(j) = mlh_mean;
            end
            varData{i} = means;

        else
            ict_path = strrep(path, '/PBLH','/mlh/');
            ict_file = strcat(filename,'.ict');
            full_path_ict = strcat(ict_path,ict_file);
            try 
                data = ICARTTreader(full_path_ict);
                mixedlayer = data.MLH;
            catch exception 
                disp(['Error: ' exception.message]);
                ict_file1 = strrep(ict_file, '.ict','_L1.ict');
                full_path_ict1 = strcat(ict_path,ict_file1);
                ict_file2 = strrep(ict_file, '.ict','_L2.ict');
                full_path_ict2 = strcat(ict_path,ict_file2);
                data1 = ICARTTreader(full_path_ict1);
                data2 = ICARTTreader(full_path_ict2);
                mlh1 = data1.MLH;
                mlh2 = data2.MLH;
                mixedlayer = [mlh1;mlh2];
            end 
            %compute average MLH around dropsonde time
            range = 10;
            means = NaN(1, length(idx));
            for j = 1:length(idx)
                i_start = idx(j) - range;
                i_end = idx(j) + range;

                if i_start < 1 || i_end > length(mixedlayer)
                    continue;
                else
                    mlh_range = mixedlayer(i_start:i_end);
                    mlh_mean = mean(mlh_range, 'omitnan');
                end

                means(j) = mlh_mean;
            end
            varData{i} = means;

        end
    end


end






