You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: UpdatePopulation.m
    path of file: ./repos/PlatEMO/PlatEMO/Algorithms/Multi-objective optimization/RGA-M1-2
    
    the code of the file until where you have to start completion: function Population = UpdatePopulation(Population,New,N)

    
function Population = UpdatePopulation(Population,New,N)
% Select NI-mu solutions from Population, and then combine them with New

%------------------------------- Copyright --------------------------------
% Copyright (c) 2023 BIMK Group. You are free to use the PlatEMO for
% research purposes. All publications which use this platform or any code
% in the platform should acknowledge the use of "PlatEMO" and reference "Ye
% Tian, Ran Cheng, Xingyi Zhang, and Yaochu Jin, PlatEMO: A MATLAB platform
% for evolutionary multi-objective optimization [educational forum], IEEE
% Computational Intelligence Magazine, 2017, 12(4): 73-87".
%--------------------------------------------------------------------------

    %% Delete the solutions in Population that may duplicate with the ones in New
    [~,index]  = setdiff(Population.objs,New.objs,'rows');
    Population = Population(index);
    
    %% Delete the duplicated solutions in current Population
    [~, Unduplicated] = unique(Population.objs,'rows');
    Population        = Population(Unduplicated);

    %% Non-dominated sorting
    if length(Population) > N
        [FrontNo,MaxFNo] = NDSort(Population.objs,sum(max(0,Population.cons),2),N);
        Next = FrontNo < MaxFNo;
        
        %% Calculate the crowding distance of each solution
        CrowdDis = CrowdingDistance(Population.objs,FrontNo);
        
        %% Select the solutions in the last front based on their crowding distances
        Last       = find(FrontNo==MaxFNo);
        [~,Rank]   = sort(CrowdDis(Last),'descend