function outSorted = matrix_sortT(matrix, sortType, dominantType)

global Po
global Pc
global IR

switch sortType
    
    case 'cut'
        
        index_c = sum(matrix == 0);
        index_r = sum(matrix == 0, 2);
        [~, sorted1] = sort(index_r, 'descend');
        [~, sorted2] = sort(index_c, 'descend');
        matrix = matrix(sorted1, sorted2);
        matrix = matrix(:, 1:dominantType);
        outSorted = matrix;
        
    case 'domC'
        
         condition = Po/(1-IR)>Pc/IR;   
        
        if condition
            
            index_r = sum(matrix~=0, 2);
            [~, sorted1] = sort(index_r, 'descend');
            
            matrix = matrix(sorted1, :);
            
            index_d = sum(matrix == -1);
            index_f = sum(matrix == 1);
            
            double_track =[index_d' index_f'];
            
            [~, track] = sortrows(double_track);
            track = flipud(track);
            track = track';
            
            matrix = matrix(:,track);
            outSorted = matrix;
            
        else
            
            index_r = sum(matrix~=0, 2);
            [~, sorted1] = sort(index_r, 'descend');
            
            matrix = matrix(sorted1, :);
            
            index_d = sum(matrix == 1);
            index_f = sum(matrix == -1);
            
            double_track =[index_d' index_f'];
            
            [~, track] = sortrows(double_track);
            track = flipud(track);
            track = track';
            
            matrix = matrix(:,track);
            outSorted = matrix;
            
        end
        
    case 'domF'
        
        condition = Po/(1-IR)>Pc/IR;      
        
        if condition
            
            index_r = sum(matrix==-1, 2);
            [~, sorted1] = sort(index_r, 'descend');
            
            matrix = matrix(sorted1, :);
            
             index_r = sum(matrix==-1);
            [~, sorted1] = sort(index_r, 'descend');
            matrix = matrix(:, sorted1);
            
            outSorted = matrix;
            
        else
            
            index_r = sum(matrix==1, 2);
            [~, sorted1] = sort(index_r, 'descend');
            
            matrix = matrix(sorted1, :);
            
           index_r = sum(matrix==1);
            [~, sorted1] = sort(index_r, 'descend');
            matrix = matrix(:, sorted1);
            outSorted = matrix;
            
        end
        
    case 'simple'
        
        if Po > Pc
            
            index_r = sum(matrix==1);
            [~, sorted1] = sort(index_r, 'descend');
            
            matrix = matrix(:,sorted1);
            
            index_r = sum(matrix== 0, 2);
            [~, sorted1] = sort(index_r, 'descend');
            
            matrix = matrix(sorted1,:);
            outSorted = matrix;
            
        else
            
            index_r = sum(matrix == 1);
            [~, sorted1] = sort(index_r, 'descend');
            
            matrix = matrix(:,sorted1);
            
            index_r = sum(matrix == 0,2);
            [~, sorted1] = sort(index_r, 'descend');
            
            matrix = matrix(sorted1,:);
            outSorted = matrix;
            
        end
        
    case 0
        
        outSorted = matrix;
        
    case 'simsirF'
        
        index_r = sum(matrix==1);
        [~, sorted1] = sort(index_r, 'descend');
        matrix = matrix(:,sorted1);
        outSorted = matrix;
        
    case 'simsirC'
        
        index_r = sum(matrix==-1);
        [~, sorted1] = sort(index_r, 'ascend');
        matrix = matrix(:,sorted1);
        outSorted = matrix;
        
end

end