Mercurial > forge
comparison main/general/repmat.m @ 0:6b33357c7561 octave-forge
Initial revision
author | pkienzle |
---|---|
date | Wed, 10 Oct 2001 19:54:49 +0000 |
parents | |
children | acd3dcc6194b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:6b33357c7561 |
---|---|
1 ## Copyright (C) 2000 Paul Kienzle | |
2 ## | |
3 ## This program is free software; you can redistribute it and/or modify | |
4 ## it under the terms of the GNU General Public License as published by | |
5 ## the Free Software Foundation; either version 2 of the License, or | |
6 ## (at your option) any later version. | |
7 ## | |
8 ## This program is distributed in the hope that it will be useful, | |
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 ## GNU General Public License for more details. | |
12 ## | |
13 ## You should have received a copy of the GNU General Public License | |
14 ## along with this program; if not, write to the Free Software | |
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
16 | |
17 ## -*- texinfo -*- | |
18 ## @deftypefn {Function File} {} repmat (@var{A}, @var{m}, @var{n}) | |
19 ## @deftypefnx {Function File} {} repmat (@var{A}, [@var{m} @var{n}]) | |
20 ## Form a block matrix of size @var{m} by @var{n}, with a copy of matrix | |
21 ## @var{A} as each element. If @var{n} is not specified, form an | |
22 ## @var{m} by @var{m} block matrix. | |
23 ## @end deftypefn | |
24 | |
25 ## Author: Paul Kienzle <pkienzle@kienzle.powernet.co.uk> | |
26 ## Created: July 2000 | |
27 | |
28 ## 2001-06-27 Paul Kienzle <pkienzle@users.sf.net> | |
29 ## * cleaner, slightly faster code | |
30 | |
31 function x = repmat (b, m, n) | |
32 if (nargin < 2 || nargin > 3) | |
33 usage ("repmat (a, m, n)"); | |
34 endif | |
35 | |
36 if nargin == 2 | |
37 if is_scalar (m) | |
38 n = m; | |
39 elseif (is_vector (m) && length (m) == 2) | |
40 n = m (2); | |
41 m = m (1); | |
42 else | |
43 error ("repmat: only builds 2D matrices") | |
44 endif | |
45 endif | |
46 | |
47 [rb, cb] = size (b); | |
48 if (isempty (b)) | |
49 x = zeros (m*rb, n*cb); | |
50 else | |
51 x = b ([1:rb]' * ones(1,m), [1:cb]' * ones(1,n)); | |
52 endif | |
53 | |
54 endfunction |