annotate scripts/general/prepad.m @ 10793:be55736a0783

Grammarcheck the documentation from m-files.
author Rik <octave@nomad.inbox5.com>
date Sun, 18 Jul 2010 20:35:16 -0700
parents e363b09a30c0
children fe3c3dfc07eb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
1 ## Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2002, 2004, 2005,
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8545
diff changeset
2 ## 2006, 2007, 2008, 2009 John W. Eaton
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
3 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
4 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
5 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
7 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
9 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
10 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
14 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
15 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
16 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
18 ## <http://www.gnu.org/licenses/>.
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 1337
diff changeset
19
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3202
diff changeset
20 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10696
diff changeset
21 ## @deftypefn {Function File} {} prepad (@var{x}, @var{l}, @var{c})
8545
faccdb98d953 postpad.m, prepad.m: doc fix
John W. Eaton <jwe@octave.org>
parents: 8436
diff changeset
22 ## @deftypefnx {Function File} {} prepad (@var{x}, @var{l}, @var{c}, @var{dim})
faccdb98d953 postpad.m, prepad.m: doc fix
John W. Eaton <jwe@octave.org>
parents: 8436
diff changeset
23 ## Prepend (append) the scalar value @var{c} to the vector @var{x}
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3202
diff changeset
24 ## until it is of length @var{l}. If the third argument is not
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3202
diff changeset
25 ## supplied, a value of 0 is used.
2311
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
26 ##
3500
7923abdeb4e5 [project @ 2000-01-31 06:35:00 by jwe]
jwe
parents: 3428
diff changeset
27 ## If @code{length (@var{x}) > @var{l}}, elements from the beginning (end) of
7923abdeb4e5 [project @ 2000-01-31 06:35:00 by jwe]
jwe
parents: 3428
diff changeset
28 ## @var{x} are removed until a vector of length @var{l} is obtained.
3652
25e84fcef38a [project @ 2000-03-31 08:50:48 by jwe]
jwe
parents: 3500
diff changeset
29 ##
25e84fcef38a [project @ 2000-03-31 08:50:48 by jwe]
jwe
parents: 3500
diff changeset
30 ## If @var{x} is a matrix, elements are prepended or removed from each row.
4870
2cbc6f37b0c2 [project @ 2004-04-21 17:30:51 by jwe]
jwe
parents: 4862
diff changeset
31 ##
2cbc6f37b0c2 [project @ 2004-04-21 17:30:51 by jwe]
jwe
parents: 4862
diff changeset
32 ## If the optional @var{dim} argument is given, then operate along this
2cbc6f37b0c2 [project @ 2004-04-21 17:30:51 by jwe]
jwe
parents: 4862
diff changeset
33 ## dimension.
8436
342f72c1df1a In prepad, add reference to postpad.
Francesco Potortì <pot@gnu.org>
parents: 7208
diff changeset
34 ## @seealso{postpad}
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3202
diff changeset
35 ## @end deftypefn
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3202
diff changeset
36
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3202
diff changeset
37 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3202
diff changeset
38 ## Created: June 1994
1337
52a3f38cbfeb [project @ 1995-08-25 02:00:18 by jwe]
jwe
parents: 904
diff changeset
39
4862
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
40 function y = prepad (x, l, c, dim)
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
41
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
42 if (nargin < 2 || nargin > 4)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5459
diff changeset
43 print_usage ();
4862
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
44 endif
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
45
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
46 if (nargin < 3 || isempty (c))
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
47 c = 0;
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
48 else
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
49 if (! isscalar (c))
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
50 error ("prepad: third argument must be empty or a scalar");
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
51 endif
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
52 endif
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
53
4862
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
54 nd = ndims (x);
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
55 sz = size (x);
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
56 if (nargin < 4)
10690
35adf2a71f3f Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
57 ## 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
58 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
59 if (isempty (dim))
4862
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
60 dim = 1;
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
61 endif
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
62 else
10690
35adf2a71f3f Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
63 if (!(isscalar (dim) && dim == fix (dim)) ||
10696
e363b09a30c0 prepad.m: Fix typo 'dimm' -> 'dim'.
Ben Abbott <bpabbott@mac.com>
parents: 10690
diff changeset
64 !(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
65 error ("prepad: DIM must be an integer and a valid dimension");
4862
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
66 endif
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
67 endif
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
68
5459
ff40c78cebf0 [project @ 2005-09-20 19:18:34 by jwe]
jwe
parents: 5307
diff changeset
69 if (! isscalar (l) || l < 0)
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
70 error ("prepad: second argument must be a positive scaler");
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
71 endif
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
72
5459
ff40c78cebf0 [project @ 2005-09-20 19:18:34 by jwe]
jwe
parents: 5307
diff changeset
73 if (dim > nd)
ff40c78cebf0 [project @ 2005-09-20 19:18:34 by jwe]
jwe
parents: 5307
diff changeset
74 sz(nd+1:dim) = 1;
ff40c78cebf0 [project @ 2005-09-20 19:18:34 by jwe]
jwe
parents: 5307
diff changeset
75 endif
ff40c78cebf0 [project @ 2005-09-20 19:18:34 by jwe]
jwe
parents: 5307
diff changeset
76
4862
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
77 d = sz (dim);
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
78
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
79 if (d >= l)
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
80 idx = cell ();
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
81 for i = 1:nd
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7017
diff changeset
82 idx{i} = 1:sz(i);
4862
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
83 endfor
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7017
diff changeset
84 idx{dim} = d-l+1:d;
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7017
diff changeset
85 y = x(idx{:});
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
86 else
4862
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
87 sz (dim) = l - d;
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
88 y = cat (dim, c * ones (sz), x);
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
89 endif
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
90
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
91 endfunction