5164
|
1 ## Copyright (C) 2004 David Bateman & Andy Adler |
|
2 ## |
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2 of the License, or |
|
6 ## (at your option) any later version. |
|
7 ## |
|
8 ## This program is distributed in the hope that it will be useful, |
|
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 ## GNU General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this program; if not, write to the Free Software |
5307
|
15 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
16 ## 02110-1301 USA |
5164
|
17 |
|
18 ## -*- texinfo -*- |
|
19 ## @deftypefn {Function File} {@var{p} =} colperm (@var{s}) |
|
20 ## Returns the column permutations such that the columns of |
|
21 ## @code{@var{s} (:, @var{p})} are ordered in terms of increase number |
|
22 ## of non-zero elements. If @var{s} is symmetric, then @var{p} is chosen |
|
23 ## such that @code{@var{s} (@var{p}, @var{p})} orders the rows and |
|
24 ## columns with increasing number of non zeros elements. |
|
25 ## @end deftypefn |
|
26 |
|
27 function p = colperm (s) |
|
28 [i, j] = spfind (s); |
|
29 idx = find (diff ([j; Inf]) != 0); |
|
30 [dummy, p] = sort (idx - [0; idx(1:(end-1))]); |
|
31 endfunction |