# HG changeset patch # User paramaniac # Date 1329328654 0 # Node ID 64319df04e336372bd1f04ea8288b8a3bee4fa49 # Parent f9ab20ba583452bc7e9bedb0e8561c970ca939c1 control-devel: work on iddata class diff -r f9ab20ba5834 -r 64319df04e33 extra/control-devel/inst/@iddata/iddata.m --- 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 diff -r f9ab20ba5834 -r 64319df04e33 extra/control-devel/inst/__iddata_dim__.m --- 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