1## Copyright (C) 2009-2016   Lukas F. Reichlin
2##
3## This file is part of LTI Syncope.
4##
5## LTI Syncope is free software: you can redistribute it and/or modify
6## it under the terms of the GNU General Public License as published by
7## the Free Software Foundation, either version 3 of the License, or
8## (at your option) any later version.
9##
10## LTI Syncope is distributed in the hope that it will be useful,
11## but WITHOUT ANY WARRANTY; without even the implied warranty of
12## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13## GNU General Public License for more details.
14##
15## You should have received a copy of the GNU General Public License
16## along with LTI Syncope.  If not, see <http://www.gnu.org/licenses/>.
17
18## -*- texinfo -*-
19## @deftypefn {Function File} {@var{rsys} =} repmat (@var{sys}, @var{m}, @var{n})
20## @deftypefnx {Function File} {@var{rsys} =} repmat (@var{sys}, [@var{m}, @var{n}])
21## @deftypefnx {Function File} {@var{rsys} =} repmat (@var{sys}, @var{m})
22## Form a block transfer matrix of @var{sys} with @var{m} copies vertically
23## and @var{n} copies horizontally.  If @var{n} is not specified, it is set to @var{m}.
24## @code{repmat (sys, 2, 3)} is equivalent to @code{[sys, sys, sys; sys, sys, sys]}.
25## @end deftypefn
26
27## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
28## Created: May 2014
29## Version: 0.1
30
31function sys = repmat (sys, x, y)
32
33  switch (nargin)
34    case 2
35      if (is_real_scalar (x))                           # repmat (sys, m)
36        y = x;
37      elseif (is_real_vector (x) && length (x) == 2)    # repmat (sys, [m, n])
38        y = x(2);
39        x = x(1);
40      else
41        error ("lti: repmat: second argument invalid");
42      endif
43    case 3                                              # repmat (sys, m, n)
44      if (! is_real_scalar (x, y))
45        error ("lti: repmat: dimensions 'm' and 'n' must be real integers");
46      endif
47    otherwise
48      print_usage ();
49  endswitch
50
51  [p, m] = size (sys);
52
53  out_idx = repmat (1:p, 1, x);
54  in_idx = repmat (1:m, 1, y);
55
56  sys = __sys_prune__ (sys, out_idx, in_idx);
57
58endfunction
59