1 function resu = permute(df, perm)
3 %% Copyright (C) 2009-2012 Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
5 %% This file is part of Octave.
7 %% Octave is free software; you can redistribute it and/or
8 %% modify it under the terms of the GNU General Public
9 %% License as published by the Free Software Foundation;
10 %% either version 2, or (at your option) any later version.
12 %% Octave is distributed in the hope that it will be useful,
13 %% but WITHOUT ANY WARRANTY; without even the implied
14 %% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 %% PURPOSE. See the GNU General Public License for more
18 %% You should have received a copy of the GNU General Public
19 %% License along with Octave; see the file COPYING. If not,
20 %% write to the Free Software Foundation, 51 Franklin Street -
21 %% Fifth Floor, Boston, MA 02110-1301, USA.
24 %# $Id: permute.m 9585 2012-02-05 15:32:46Z cdemills $
29 if (length(df._cnt) >= length(perm)),
30 resu._cnt = df._cnt(perm);
32 resu._cnt = [df._cnt 1](perm);
35 if (ndims(df._ridx) < 3),
36 resu._ridx = permute(df._ridx, [min(perm(1), 2) min(perm(2:end))]);
38 resu._ridx = permute(df._ridx, perm);
41 if (size(resu._ridx, 1) < resu._cnt(1)),
42 %# adjust index size, if required
43 resu._ridx(end+1:resu._cnt(1), :, :) = NA;
47 resu._name{1} = df._name{2};
48 resu._over{1} = df._over{2};
49 indc = length(resu._name{1});
50 indi = resu._cnt(1) - indc;
52 %# generate a name for the new row(s)
53 dummy = cstrcat(repmat('_', indi, 1), ...
54 strjust(num2str(indc + (1:indi).'), 'left'));
55 resu._name{1}(indc + (1:indi)) = cellstr(dummy);
56 resu._over{1}(1, indc + (1:indi)) = true;
59 resu._name{1} = df._name{1};
60 resu._over{1} = df._over{1};
65 resu._name{2} = df._name{2};
66 resu._over{2} = df._over{2};
68 resu._name{2} = df._name{1};
69 resu._over{2} = df._over{1};
72 if (isempty(resu._name{2})),
75 indc = length(resu._name{2});
77 indi = resu._cnt(2) - indc;
79 %# generate a name for the new column(s)
80 dummy = cstrcat(repmat('_', indi, 1), ...
81 strjust(num2str(indc + (1:indi).'), 'left'));
82 resu._name{2}(indc + (1:indi)) = cellstr(dummy);
83 resu._over{2}(1, indc + (1:indi)) = true;
87 %# recompute the new type
88 dummy = zeros(0, class(sum(cellfun(@(x) zeros(1, class(x(1))),\
90 resu._type(1:resu._cnt(2)) = class(dummy);
91 dummy = permute(df_whole(df), perm);
92 for indi = 1:resu._cnt(2),
93 resu._data{indi} = squeeze(dummy(:, indi, :));
94 resu._rep{indi} = 1:size(resu._data{indi}, 2);
97 if (1 == perm(1)), %# blank operation
98 resu._type = df._type;
99 resu._data = df._data;
102 for indi = 1:resu._cnt(2),
103 unfolded = df._data{indi}(:, df._rep{indi});
104 resu._data{indi} = permute(unfolded, [2 1]);
105 resu._rep{indi} = 1:size(resu._data{indi}, 2);
106 resu._type{indi} = df._type{indi};