2847
|
1 ## Copyright (C) 1996, 1997 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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
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 |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
2303
|
19 |
3428
|
20 ## See prepad. |
|
21 |
|
22 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
|
23 ## Created: June 1994 |
904
|
24 |
2311
|
25 function y = postpad (x, l, c) |
561
|
26 |
1337
|
27 if (nargin == 2) |
561
|
28 c = 0; |
1337
|
29 elseif (nargin < 2 || nargin > 3) |
|
30 usage ("postpad (x, l) or postpad (x, l, c)"); |
561
|
31 endif |
|
32 |
2716
|
33 if (! is_vector (x)) |
1337
|
34 error ("first argument must be a vector"); |
|
35 elseif (! is_scalar (l)) |
|
36 error ("second argument must be a scaler"); |
561
|
37 endif |
|
38 |
1337
|
39 if (l < 0) |
|
40 error ("second argument must be non-negative"); |
561
|
41 endif |
|
42 |
1337
|
43 lx = length (x); |
561
|
44 |
1337
|
45 if (lx >= l) |
561
|
46 y = x(1:l); |
|
47 else |
1337
|
48 if (rows (x) > 1) |
|
49 tmp = c * ones (l-lx, 1); |
|
50 y = [x; tmp]; |
561
|
51 else |
1337
|
52 tmp = c * ones (1, l-lx); |
|
53 y = [x, tmp]; |
561
|
54 endif |
|
55 endif |
|
56 |
|
57 endfunction |