Mercurial > octave-nkf
annotate scripts/general/postpad.m @ 11523:fd0a3ac60b0e
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 14 Jan 2011 05:47:45 -0500 |
parents | fe3c3dfc07eb |
children | 6bac61388876 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1994-2011 John W. Eaton |
2313 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
2313 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
2303 | 18 |
3458 | 19 ## -*- texinfo -*- |
10690
35adf2a71f3f
Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
20 ## @deftypefn {Function File} {} postpad (@var{x}, @var{l}, @var{c}) |
8545
faccdb98d953
postpad.m, prepad.m: doc fix
John W. Eaton <jwe@octave.org>
parents:
8433
diff
changeset
|
21 ## @deftypefnx {Function File} {} postpad (@var{x}, @var{l}, @var{c}, @var{dim}) |
8433
3292bd1bbaa4
Cross reference between postpad and resize
Francesco Potortì <pot@gnu.org>
parents:
7208
diff
changeset
|
22 ## @seealso{prepad, resize} |
3458 | 23 ## @end deftypefn |
3428 | 24 |
25 ## Author: Tony Richardson <arichard@stark.cc.oh.us> | |
26 ## Created: June 1994 | |
904 | 27 |
4862 | 28 function y = postpad (x, l, c, dim) |
29 | |
30 if (nargin < 2 || nargin > 4) | |
6046 | 31 print_usage (); |
4862 | 32 endif |
33 | |
34 if (nargin < 3 || isempty (c)) | |
35 c = 0; | |
36 else | |
37 if (! isscalar (c)) | |
38 error ("postpad: third argument must be empty or a scalar"); | |
39 endif | |
40 endif | |
561 | 41 |
4862 | 42 nd = ndims (x); |
43 sz = size (x); | |
44 if (nargin < 4) | |
10690
35adf2a71f3f
Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
45 ## Find the first non-singleton dimension |
35adf2a71f3f
Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
46 dim = find (sz > 1, 1); |
35adf2a71f3f
Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
47 if (isempty (dim)) |
4862 | 48 dim = 1; |
49 endif | |
50 else | |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10690
diff
changeset
|
51 if (!(isscalar (dim) && dim == fix (dim)) |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10690
diff
changeset
|
52 || !(1 <= dim && dim <= nd)) |
10690
35adf2a71f3f
Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
53 error ("postpad: DIM must be an integer and a valid dimension"); |
4862 | 54 endif |
561 | 55 endif |
56 | |
5459 | 57 if (! isscalar (l) || l < 0) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
58 error ("postpad: second argument must be a positive scaler"); |
561 | 59 endif |
60 | |
5459 | 61 if (dim > nd) |
62 sz(nd+1:dim) = 1; | |
63 endif | |
64 | |
4862 | 65 d = sz (dim); |
5459 | 66 |
4862 | 67 if (d >= l) |
68 idx = cell (); | |
69 for i = 1:nd | |
7208 | 70 idx{i} = 1:sz(i); |
4862 | 71 endfor |
7208 | 72 idx{dim} = 1:l; |
73 y = x(idx{:}); | |
561 | 74 else |
4862 | 75 sz (dim) = l - d; |
76 y = cat (dim, x, c * ones (sz)); | |
561 | 77 endif |
78 | |
79 endfunction |