function new_int = LEM_merge_intervals_new(int1,int2)
% LEM_merge_intervals - merge two intervals
% On input:
%     int1 (interval): first interval
%     int2 (interval): interval 2
% On output:
%     new_int (interval): merged interval
% Call:
%     ni = LEM_merge_intervals(i1,i2);
% Author:
%     T. Henderson
%     UU
%     Fall 2020
%

if isempty(int1)&isempty(int2)
    new_int = [];
    return
end

new_int = [int1;int2];
[len_int2,dummy] = size(int2);
if len_int2>10
    int2 = int2(1:10,:);
end
[vals,indexes] = sort(new_int(:,1));
new_int = new_int(indexes,:);
num_new_int = length(new_int(:,1));
k = 0;
while k<num_new_int-1
    k = k + 1;
    if new_int(k,1)==new_int(k+1,1)
        new_int(k,2) = min(new_int(k,2),new_int(k+1,2));
        new_int(k+1,:) = [];
    else
        k = k + 1;
    end
end
