--- a/inst/@lti/connect.m
+++ b/inst/@lti/connect.m
@@ -1,4 +1,4 @@
-## Copyright (C) 2009   Lukas F. Reichlin
+## Copyright (C) 2009, 2013   Lukas F. Reichlin
 ##
 ## This file is part of LTI Syncope.
 ##
@@ -22,38 +22,91 @@
 
 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
 ## Created: October 2009
-## Version: 0.1
+## Version: 0.2
 
-function sys = connect (sys, cm, in_idx, out_idx)
+function sys = connect (varargin)
 
-  if (nargin != 4)
+  if (nargin < 2)
     print_usage ();
   endif
+  
+  if (is_real_matrix (varargin{2}))     # connect (sys, cm, in_idx, out_idx)
+  
+    if (nargin != 4)
+      print_usage ();
+    endif
+    
+    sys = varargin{1};
+    cm = varargin{2};
+    in_idx = varargin{3};
+    out_idx = varargin{4};
 
-  [p, m] = size (sys);
-  [cmrows, cmcols] = size (cm);
+    [p, m] = size (sys);
+    [cmrows, cmcols] = size (cm);
 
-  ## TODO: proper argument checking
-  ## TODO: name-based interconnections
-  ## TODO: replace nested for-if statement
+    ## TODO: proper argument checking
+    ## TODO: replace nested for-if statement
 
-  if (! is_real_matrix (cm))
-    error ("connect: second argument must be a matrix with real-valued coefficients");
+    ## if (! is_real_matrix (cm))
+    ##   error ("connect: second argument must be a matrix with real-valued coefficients");
+    ## endif
+
+    M = zeros (m, p);
+    in = cm(:, 1);
+    out = cm(:, 2:cmcols);
+
+    for a = 1 : cmrows
+      for b = 1 : cmcols-1
+        if (out(a, b) != 0)
+          M(in(a, 1), abs (out(a, b))) = sign (out(a, b));
+        endif
+      endfor
+    endfor
+
+  else                                  # connect (sys1, sys2, ..., sysN, in_idx, out_idx)
+
+    lti_idx = cellfun (@isa, varargin, {"lti"});
+    sys = append (varargin{lti_idx});
+    io_idx = ! lti_idx;
+    
+    if (nnz (io_idx) != 2)
+      print_usage ();
+    endif
+    
+    in_idx = varargin(io_idx){1};
+    out_idx = varargin(io_idx){2};
+
+    inname = sys.inname;
+    outname = sys.outname;
+    
+    ioname = intersect (inname, outname);
+    
+    tmp = cellfun (@(x) find (strcmp (inname, x)(:)), ioname, "uniformoutput", false);
+    inputs = vertcat (tmp{:});  # there could be more than one input with the same name
+    
+    [p, m] = size (sys);
+    M = zeros (m, p);
+    for k = 1 : length (inputs)
+      outputs = strcmp (outname, inname(inputs(k)));
+      M(inputs(k), :) = outputs;
+    endfor
+
   endif
-
-  M = zeros (m, p);
-  in = cm(:, 1);
-  out = cm(:, 2:cmcols);
-
-  for a = 1 : cmrows
-    for b = 1 : cmcols-1
-      if (out(a, b) != 0)
-        M(in(a, 1), abs (out(a, b))) = sign (out(a, b));
-      endif
-    endfor
-  endfor
 
   sys = __sys_connect__ (sys, M);
   sys = __sys_prune__ (sys, out_idx, in_idx);
 
 endfunction
+
+
+%!shared T, Texp
+%! P = Boeing707;
+%! I = ss (-eye (2));
+%! I.inname = P.outname;
+%! I.outname = P.inname;
+%! T = connect (P, I, P.inname, P.outname);
+%! Texp = feedback (P);
+%!assert (T.a, Texp.a, 1e-4);
+%!assert (T.b, Texp.b, 1e-4);
+%!assert (T.c, Texp.c, 1e-4);
+%!assert (T.d, Texp.d, 1e-4);