# v_mintrace

## PURPOSE

V_MINTRACE find row permutation to minimize the trace p=(x)

## SYNOPSIS

function p=v_mintrace(x)

## DESCRIPTION

    V_MINTRACE find row permutation to minimize the trace p=(x)
    Inputs:    x(n,n)  is a square real-valued matrix

    Outputs:   p(n,1)  is the row permutation that minimizes the trace
                       so that trace(x(p,:)) is as small as possible

## CROSS-REFERENCE INFORMATION

This function calls:

- v_permutes V_PERMUTES All N! permutations of 1:N + signatures [P,S]=(N)

This function is called by:

## SOURCE CODE

    0001 function p=v_mintrace(x)
    0002 %V_MINTRACE find row permutation to minimize the trace p=(x)
    0003 %Inputs:    x(n,n)  is a square real-valued matrix
    0004 %
    0005 %Outputs:   p(n,1)  is the row permutation that minimizes the trace
    0006 %                   so that trace(x(p,:)) is as small as possible
    0007
    0008 %      Copyright (C) Mike Brookes 2012-2013
    0009 %      Version: $Id: v_mintrace.m 10865 2018-09-21 17:22:45Z dmb $
    0010 %
    0011 %   VOICEBOX is a MATLAB toolbox for speech processing.
    0012 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
    0013 %
    0014 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0015 %   This program is free software; you can redistribute it and/or modify
    0016 %   it under the terms of the GNU Lesser General Public License as published by
    0017 %   the Free Software Foundation; either version 3 of the License, or
    0018 %   (at your option) any later version.
    0019 %
    0020 %   This program is distributed in the hope that it will be useful,
    0021 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
    0022 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0023 %   GNU Lesser General Public License for more details.
    0024 %
    0025 %   You can obtain a copy of the GNU Lesser General Public License from
    0026 %   https://www.gnu.org/licenses/ .
    0027 %
    0028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0029 n=size(x,1);    % input x must be square
    0030 p=v_permutes(n);  % try all permutations
    0031 c=0:n:n^2-1;    % convert olumns to single indexing
    0032 [v,i]=min(sum(x(p+c(ones(length(p),1),:)),2));
    0033 p=p(i,:)';
    0034