Mercurial > hg > octave-nkf
annotate scripts/general/postpad.m @ 9037:4cb9f994dcec
Documentation cleanup of var.texi, expr.texi, eval.texi
Spellcheck
Style check (particularly for two spaces after period)
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Sun, 22 Mar 2009 08:41:49 -0700 |
parents | eb63fbe60fab |
children | 95c3e38098bf |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2002, 2004, 2005, |
8920 | 2 ## 2006, 2007, 2008, 2009 John W. Eaton |
2313 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
2303 | 19 |
3458 | 20 ## -*- texinfo -*- |
3500 | 21 ## @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
|
22 ## @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
|
23 ## @seealso{prepad, resize} |
3458 | 24 ## @end deftypefn |
3428 | 25 |
26 ## Author: Tony Richardson <arichard@stark.cc.oh.us> | |
27 ## Created: June 1994 | |
904 | 28 |
4862 | 29 function y = postpad (x, l, c, dim) |
30 | |
31 if (nargin < 2 || nargin > 4) | |
6046 | 32 print_usage (); |
4862 | 33 endif |
34 | |
35 if (nargin < 3 || isempty (c)) | |
36 c = 0; | |
37 else | |
38 if (! isscalar (c)) | |
39 error ("postpad: third argument must be empty or a scalar"); | |
40 endif | |
41 endif | |
561 | 42 |
4862 | 43 nd = ndims (x); |
44 sz = size (x); | |
45 if (nargin < 4) | |
46 %% Find the first non-singleton dimension | |
47 dim = 1; | |
48 while (dim < nd + 1 && sz (dim) == 1) | |
49 dim = dim + 1; | |
50 endwhile | |
51 if (dim > nd) | |
52 dim = 1; | |
53 endif | |
54 else | |
55 if (! (isscalar (dim) && dim == round (dim)) && dim > 0 && | |
56 dim < (nd + 1)) | |
57 error ("postpad: dim must be an integer and valid dimension"); | |
58 endif | |
561 | 59 endif |
60 | |
5459 | 61 if (! isscalar (l) || l < 0) |
4862 | 62 error ("second argument must be a positive scaler"); |
561 | 63 endif |
64 | |
5459 | 65 if (dim > nd) |
66 sz(nd+1:dim) = 1; | |
67 endif | |
68 | |
4862 | 69 d = sz (dim); |
5459 | 70 |
4862 | 71 if (d >= l) |
72 idx = cell (); | |
73 for i = 1:nd | |
7208 | 74 idx{i} = 1:sz(i); |
4862 | 75 endfor |
7208 | 76 idx{dim} = 1:l; |
77 y = x(idx{:}); | |
561 | 78 else |
4862 | 79 sz (dim) = l - d; |
80 y = cat (dim, x, c * ones (sz)); | |
561 | 81 endif |
82 | |
83 endfunction |