Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Diff of /inst/@lti/__lti_group__.m [2c098b] .. [b109d7] Maximize Restore

  Switch to side-by-side view

--- a/inst/@lti/__lti_group__.m
+++ b/inst/@lti/__lti_group__.m
@@ -34,6 +34,18 @@
   retlti.outname = [lti1.outname;
                     lti2.outname];
 
+  if (nfields (lti1.ingroup) || nfields (lti2.ingroup))
+    m1 = numel (lti1.inname);
+    lti2_ingroup = structfun (@(x) x + m1, lti2.ingroup, "uniformoutput", false);
+    retlti.ingroup = __merge_struct__ (lti1.ingroup, lti2_ingroup, "in");
+  endif
+  
+  if (nfields (lti1.outgroup) || nfields (lti2.outgroup))
+    p1 = numel (lti1.outname);
+    lti2_outgroup = structfun (@(x) x + p1, lti2.outgroup, "uniformoutput", false);
+    retlti.outgroup = __merge_struct__ (lti1.outgroup, lti2_outgroup, "out");
+  endif
+
   if (lti1.tsam == lti2.tsam)
     retlti.tsam = lti1.tsam;
   elseif (lti1.tsam == -2)
@@ -49,3 +61,34 @@
   endif
 
 endfunction
+
+
+function ret = __merge_struct__ (a, b, iostr)
+
+  ## FIXME: this is too complicated;
+  ##        isn't there a simple function for this task?
+
+  ## bug #40224: orderfields (struct ()) errors out in Octave 3.6.4
+  ## therefore use nfields to check for empty structs
+  if (nfields (a))
+    a = orderfields (a);
+  endif
+  if (nfields (b))
+    b = orderfields (b);
+  endif
+
+  fa = fieldnames (a);
+  fb = fieldnames (b);
+  [fi, ia, ib] = intersect (fa, fb);
+  ca = struct2cell (a);
+  cb = struct2cell (b);
+
+  for k = numel (fi) : -1 : 1
+    ca{ia(k)} = vertcat (ca{ia(k)}(:), cb{ib(k)}(:));
+    fb(ib(k)) = [];
+    cb(ib(k)) = [];
+  endfor
+  
+  ret = cell2struct ([ca; cb], [fa; fb]);
+
+endfunction