function [x1,y1,x2,y2] = cutLongerCurve(x1,y1,x2,y2)
    if x1(end) > x2(end)
        endPointY = interp1(x1,y1,x2(end));
        endPointX = x2(end);
        idxOfLesserX = find(x1<endPointX);
        x1 = x1(1:idxOfLesserX(end));
        x1(end) = endPointX;
        y1 = y1(1:idxOfLesserX(end));
        y1(end) = endPointY;
    else
        endPointY = interp1(x2,y2,x1(end));
        endPointX = x1(end);
        idxOfLesserX = find(x2<endPointX);
        x2 = x2(1:idxOfLesserX(end));
        x2(end) = endPointX;
        y2 = y2(1:idxOfLesserX(end));
        y2(end) = endPointY;
    end
end
