Mercurial > hg > octave-nkf
annotate scripts/general/prepad.m @ 9665:1dba57e9d08d
use blas_trans_type for xgemm
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sat, 26 Sep 2009 10:41:07 +0200 |
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 |
3428 | 20 ## -*- texinfo -*- |
3500 | 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 | 24 ## until it is of length @var{l}. If the third argument is not |
25 ## supplied, a value of 0 is used. | |
2311 | 26 ## |
3500 | 27 ## If @code{length (@var{x}) > @var{l}}, elements from the beginning (end) of |
28 ## @var{x} are removed until a vector of length @var{l} is obtained. | |
3652 | 29 ## |
30 ## If @var{x} is a matrix, elements are prepended or removed from each row. | |
4870 | 31 ## |
32 ## If the optional @var{dim} argument is given, then operate along this | |
33 ## dimension. | |
8436
342f72c1df1a
In prepad, add reference to postpad.
Francesco Potortì <pot@gnu.org>
parents:
7208
diff
changeset
|
34 ## @seealso{postpad} |
3428 | 35 ## @end deftypefn |
36 | |
37 ## Author: Tony Richardson <arichard@stark.cc.oh.us> | |
38 ## Created: June 1994 | |
1337 | 39 |
4862 | 40 function y = prepad (x, l, c, dim) |
41 | |
42 if (nargin < 2 || nargin > 4) | |
6046 | 43 print_usage (); |
4862 | 44 endif |
45 | |
46 if (nargin < 3 || isempty (c)) | |
47 c = 0; | |
48 else | |
49 if (! isscalar (c)) | |
50 error ("prepad: third argument must be empty or a scalar"); | |
51 endif | |
52 endif | |
559 | 53 |
4862 | 54 nd = ndims (x); |
55 sz = size (x); | |
56 if (nargin < 4) | |
57 %% Find the first non-singleton dimension | |
58 dim = 1; | |
59 while (dim < nd + 1 && sz (dim) == 1) | |
60 dim = dim + 1; | |
61 endwhile | |
62 if (dim > nd) | |
63 dim = 1; | |
64 endif | |
65 else | |
66 if (! (isscalar (dim) && dim == round (dim)) && dim > 0 && | |
67 dim < (nd + 1)) | |
68 error ("prepad: dim must be an integer and valid dimension"); | |
69 endif | |
559 | 70 endif |
71 | |
5459 | 72 if (! isscalar (l) || l < 0) |
4862 | 73 error ("second argument must be a positive scaler"); |
559 | 74 endif |
75 | |
5459 | 76 if (dim > nd) |
77 sz(nd+1:dim) = 1; | |
78 endif | |
79 | |
4862 | 80 d = sz (dim); |
81 | |
82 if (d >= l) | |
83 idx = cell (); | |
84 for i = 1:nd | |
7208 | 85 idx{i} = 1:sz(i); |
4862 | 86 endfor |
7208 | 87 idx{dim} = d-l+1:d; |
88 y = x(idx{:}); | |
559 | 89 else |
4862 | 90 sz (dim) = l - d; |
91 y = cat (dim, c * ones (sz), x); | |
559 | 92 endif |
93 | |
94 endfunction |