From: <par...@us...> - 2012-02-15 17:57:41
|
Revision: 9626 http://octave.svn.sourceforge.net/octave/?rev=9626&view=rev Author: paramaniac Date: 2012-02-15 17:57:34 +0000 (Wed, 15 Feb 2012) Log Message: ----------- control-devel: work on iddata class Modified Paths: -------------- trunk/octave-forge/extra/control-devel/inst/@iddata/iddata.m trunk/octave-forge/extra/control-devel/inst/__iddata_dim__.m Modified: trunk/octave-forge/extra/control-devel/inst/@iddata/iddata.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/@iddata/iddata.m 2012-02-15 11:54:15 UTC (rev 9625) +++ trunk/octave-forge/extra/control-devel/inst/@iddata/iddata.m 2012-02-15 17:57:34 UTC (rev 9626) @@ -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 Modified: trunk/octave-forge/extra/control-devel/inst/__iddata_dim__.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/__iddata_dim__.m 2012-02-15 11:54:15 UTC (rev 9625) +++ trunk/octave-forge/extra/control-devel/inst/__iddata_dim__.m 2012-02-15 17:57:34 UTC (rev 9626) @@ -2,8 +2,34 @@ ## 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"); endif @@ -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 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |