www.gusucode.com > GAVPai_Book_MathworksCntrlFileEx_May2019 > GAVPai_Book_MathworksCntrlFileEx_May2019/determine_bounds.m

    % Given the population of randomly generated chromosomes representing the 
% buy and sell proportions of weights of individual assets, the function determines 
% the upper and lower bounds for each of the asset weights, based on
% whether the weight represents a buy or a sell

function [lowup_limits ] = determine_bounds( popln, pos_low_limits, pos_up_limits, neg_low_limits, neg_up_limits )

[row, col]=size(popln);

lowup_limits = cell(1,row);
for i =1: row
    
    for j=1:col
        if (popln(i,j) >= 0) 
             lmts(1,j)=pos_low_limits(j);
             lmts(2,j)=pos_up_limits(j);
        else
             lmts(1,j)=neg_low_limits(j);
             lmts(2,j)=neg_up_limits(j);
        end
    end
    lowup_limits{i}=[lmts(1,:);lmts(2,:)];
    
end