changeset 9440:64319df04e33 octave-forge

control-devel: work on iddata class
author paramaniac
date Wed, 15 Feb 2012 17:57:34 +0000
parents f9ab20ba5834
children d672dbb87d5a
files extra/control-devel/inst/@iddata/iddata.m extra/control-devel/inst/__iddata_dim__.m
diffstat 2 files changed, 54 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/extra/control-devel/inst/@iddata/iddata.m	Wed Feb 15 11:54:15 2012 +0000
+++ b/extra/control-devel/inst/@iddata/iddata.m	Wed Feb 15 17:57:34 2012 +0000
@@ -2,20 +2,21 @@
 ## Created: October 2011
 ## Version: 0.1
 
-function dat = iddata (y = [], u = [], tsam = [], varargin)
+function dat = iddata (y = [], u = [], tsam = -1, varargin)
 
   if (nargin == 1 && isa (y, "iddata"))
     dat = y;
     return;
-  elseif (nargin < 3)
+  elseif (nargin < 2)
     print_usage ();
   endif
 
-  if (! issample (tsam, 1))
+  if (! issample (tsam, -1))
     error ("iddata: invalid sampling time");
   endif
 
-  [p, m] = __iddata_dim__ (y, u);
+  [y, u] = __adjust_iddata__ (y, u);
+  [p, m, e] = __iddata_dim__ (y, u);
 
   outname = repmat ({""}, p, 1);
   inname = repmat ({""}, m, 1);
@@ -31,4 +32,23 @@
     dat = set (dat, varargin{:});
   endif
 
-endfunction
\ No newline at end of file
+endfunction
+
+
+function [y, u] = __adjust_iddata__ (y, u)
+
+  if (iscell (y))
+    y = reshape (y, [], 1);
+  else
+    y = {y};
+  endif
+  
+  if (isempty (u))
+    u = [];     # avoid [](nx0) and the like
+  elseif (iscell (u))
+    u = reshape (u, [], 1);
+  else
+    u = {u};
+  endif
+
+endfunction
--- a/extra/control-devel/inst/__iddata_dim__.m	Wed Feb 15 11:54:15 2012 +0000
+++ b/extra/control-devel/inst/__iddata_dim__.m	Wed Feb 15 17:57:34 2012 +0000
@@ -2,7 +2,33 @@
 ## Created: October 2011
 ## Version: 0.1
 
-function [p, m] = __iddata_dim__ (y, u)
+function [p, m, e] = __iddata_dim__ (y, u)
+
+  e = numel (y);                        # number of experiments
+
+  if (isempty (u))                      # time series data, outputs only
+    [p, m] = cellfun (@__experiment_dim__, y, "uniformoutput", false);
+  elseif (e == numel (u))               # outputs and inputs present
+    [p, m] = cellfun (@__experiment_dim__, y, u, "uniformoutput", false);
+  else
+    error ("iddata: require input and output data with matching number of experiments");
+  endif
+
+  if (e > 1 && ! isequal (p{:}))
+    error ("iddata: require identical number of output channels for all experiments");
+  endif
+
+  if (e > 1 && ! isequal (m{:}))
+    error ("iddata: require identical number of input channels for all experiments");
+  endif
+
+  p = p{1};
+  m = m{1};
+
+endfunction
+
+
+function [p, m] = __experiment_dim__ (y, u = [])
 
   if (! is_real_matrix (y, u))
     error ("iddata: inputs and outputs must be real");
@@ -11,7 +37,7 @@
   [ly, p] = size (y);
   [lu, m] = size (u);
   
-  if (ly != lu)
+  if (! isempty (u) && ly != lu)
     error ("iddata: matrices 'y' and 'u' must have the same number of samples (rows)");
   endif
 
@@ -23,4 +49,4 @@
     warning ("iddata: more inputs than samples - matrice 'u' should probably be transposed");
   endif
 
-endfunction
\ No newline at end of file
+endfunction