changeset 9556:2522fc8f74d8 octave-forge

control-devel: draft code for iddata cat method
author paramaniac
date Sun, 04 Mar 2012 15:58:30 +0000
parents f38dc4df5988
children 71f71a885bcd
files extra/control-devel/devel/test_iddata.m extra/control-devel/inst/@iddata/cat.m extra/control-devel/inst/@iddata/subsasgn.m
diffstat 3 files changed, 87 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/extra/control-devel/devel/test_iddata.m	Sun Mar 04 15:21:59 2012 +0000
+++ b/extra/control-devel/devel/test_iddata.m	Sun Mar 04 15:58:30 2012 +0000
@@ -15,3 +15,18 @@
 d = iddata ({(1:10).', (21:25).'}, {(31:40).', (41:45).'})
 
 e = iddata ({(1:10).', (21:25).', (21:125).'}, {(31:40).', (41:45).', (41:145).'})
+
+
+oy = ones (200, 5);
+ou = ones (200, 4);
+y = repmat ({oy}, 6, 1);
+u = repmat ({ou}, 6, 1);
+
+f = iddata (y, u)
+%{
+f.expname = strseq ("experiment", 1:6)
+f.expname(2) = "value 1"
+f.expname{2} = "value 2"
+%}
+
+cat (4, f, f, f)
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extra/control-devel/inst/@iddata/cat.m	Sun Mar 04 15:58:30 2012 +0000
@@ -0,0 +1,60 @@
+## Copyright (C) 2012   Lukas F. Reichlin
+##
+## This file is part of LTI Syncope.
+##
+## LTI Syncope is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## LTI Syncope is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with LTI Syncope.  If not, see <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {@var{dat} =} cat (@var{dim}, @var{dat1}, @var{dat2}, @dots{})
+## Concatenation of iddata objects along dimension @var{dim}.
+## @end deftypefn
+
+## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
+## Created: March 2012
+## Version: 0.1
+
+function dat = cat (dim, varargin)
+
+  switch (dim)
+    case 1      # add samples; p, m, e identical
+      %[~, p, m, e]
+      %nvec = cellfun (@size
+      [~, p, m, e] = cellfun (@size, varargin, "uniformoutput", false)
+      
+      %y = cellfun (@(dat) vertcat (dat.y) 
+      %dat = cellfun (@iddata, varargin)
+      #y = cellfun (@vertcat
+      
+      ycell = cellfun (@(dat) dat.y, varargin, "uniformoutput", false)
+
+
+
+      %varargin{:}.y
+      %varargin(:).y
+    case 2      # horzcat, same outputs; 
+    
+    case 3      # vertcat, same inputs
+    
+    case 4      # add experiments
+      tmp = cellfun (@iddata, varargin);
+      
+      y = vertcat (tmp.y);
+      u = vertcat (tmp.u);
+      
+      dat = iddata (y, u);
+      
+  
+  endswitch
+
+endfunction
\ No newline at end of file
--- a/extra/control-devel/inst/@iddata/subsasgn.m	Sun Mar 04 15:21:59 2012 +0000
+++ b/extra/control-devel/inst/@iddata/subsasgn.m	Sun Mar 04 15:58:30 2012 +0000
@@ -26,12 +26,19 @@
 function dat = subsasgn (dat, idx, val)
 
   switch (idx(1).type)
-    case "."
-      if (length (idx) == 1)
+    case "()"                                                   # dat(...) = val
+      if (length (idx(1).subs) == 1 && isa (val, "iddata"))     # dat(x) = dat, required by cat for ...
+        dat(idx.subs{:}) = val;                                 # dat = cellfun (@iddata, varargin)
+      else                                                      # dat(...) = val, general case
+        error ("iddata: subsasgn type not implemented yet");
+      endif
+
+    case "."                                                    # dat.y... = val
+      if (length (idx) == 1)                                    # dat.y = val
         dat = set (dat, idx.subs, val);
-      else
-        prop = idx(1).subs;
-        dat = set (dat, prop, subsasgn (get (dat, prop), idx(2:end), val));
+      else                                                      # dat.y(...) = val, dat.expname{3} = val
+        key = idx(1).subs;
+        dat = set (dat, key, subsasgn (get (dat, key), idx(2:end), val));
       endif
     otherwise
       error ("iddata: subsasgn: invalid subscripted assignment type");