function [minf,minID] = minDeTrend(f)
%MINDETREND Finds minimum cost and its index form a table of values where
%each row represents a design-point with multi-objective cost values in
%columns

%  Copyright 2020 The MathWorks, Inc.

F = f;
N = size(F,1);
ID = (1:N)';
for i = 1:size(F,2)+1 % iterate for the number of columns
    % row-wise maximum values
    maxF = max(F,[],2); 
    idinf = (maxF==-inf);
    F(idinf,:) = [];
    ID(idinf) = [];
    maxF(idinf)=[];
    if isempty(F)
        break;
    end
    % minimum of maximum row-wise column value
    minF = min(maxF); 
    % rows that have tha same minimum value
    idy = maxF==minF; 
    % Extract rows (and indeces) with same minimum of maximum value
    F = F(idy,:); 
    ID = ID(idy,:);
    % Remove duplicate maximum values (set to -inf to remove in next loop iteration)
    F(F==minF) = -inf;
    minID = ID(1);
end
minf = max(f(minID,:));