From: <par...@us...> - 2012-03-05 17:33:00
|
Revision: 9747 http://octave.svn.sourceforge.net/octave/?rev=9747&view=rev Author: paramaniac Date: 2012-03-05 17:32:53 +0000 (Mon, 05 Mar 2012) Log Message: ----------- control-devel: touch up cat method Modified Paths: -------------- trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m Modified: trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m 2012-03-05 17:11:29 UTC (rev 9746) +++ trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m 2012-03-05 17:32:53 UTC (rev 9747) @@ -31,29 +31,25 @@ switch (dim) case 1 # vertcat - catenate samples - if (nargin > 2) # isequal only works for 2 or more arguments (dim doesn't count) - if (! isequal (e{:})) - error ("iddata: cat: number of experiments don't match [%s]", \ - num2str (cell2mat (e), "%d ")); - endif - if (! isequal (p{:}) - error ("iddata: cat: number of outputs don't match [%s]", \ - num2str (cell2mat (p), "%d ")); - endif - if (! isequal (m{:}) - error ("iddata: cat: number of inputs don't match [%s]", \ - num2str (cell2mat (m), "%d ")); - endif - endif + check_experiments (e); + check_outputs (p); + check_inputs (m); y = cellfun (@vertcat, tmp.y, "uniformoutput", false); u = cellfun (@vertcat, tmp.u, "uniformoutput", false); case 2 # horzcat - catenate channels; + check_experiments (e); + check_samples (n); + y = cellfun (@horzcat, tmp.y, "uniformoutput", false); u = cellfun (@horzcat, tmp.u, "uniformoutput", false); case 3 # merge - catenate experiments + check_outputs (p); + check_inputs (m); + check_samples (n); + y = vertcat (tmp.y); u = vertcat (tmp.u); @@ -66,4 +62,44 @@ endfunction -%!error (cat (1, iddata (1, 1), iddata ({2, 3}, {2, 3}))); \ No newline at end of file +function check_experiments (e) + + if (numel (e) > 1 && ! isequal (e{:})) + error ("iddata: cat: number of experiments don't match [%s]", \ + num2str (cell2mat (e), "%d ")); + endif + +endfunction + + +function check_outputs (p) + + if (numel (p) > 1 && ! isequal (p{:})) + error ("iddata: cat: number of outputs don't match [%s]", \ + num2str (cell2mat (p), "%d ")); + endif + +endfunction + + +function check_inputs (m) + + if (numel (m) > 1 && ! isequal (m{:})) + error ("iddata: cat: number of inputs don't match [%s]", \ + num2str (cell2mat (m), "%d ")); + endif + +endfunction + + +function check_samples (n) + + if (numel (n) > 1 && ! isequal (n{:})) + error ("iddata: cat: number of samples don't match [%s]", \ + num2str (cell2mat (n), "%d ")); + endif + +endfunction + + +%!error (cat (1, iddata (1, 1), iddata ({2, 3}, {2, 3}))); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-03-07 17:23:02
|
Revision: 9768 http://octave.svn.sourceforge.net/octave/?rev=9768&view=rev Author: paramaniac Date: 2012-03-07 17:22:56 +0000 (Wed, 07 Mar 2012) Log Message: ----------- control-devel: add comments Modified Paths: -------------- trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m Modified: trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m 2012-03-07 17:06:48 UTC (rev 9767) +++ trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m 2012-03-07 17:22:56 UTC (rev 9768) @@ -127,10 +127,14 @@ function bool = compare_strings (str, varargin) if (nargin > 1) + ## compare n-th string of first cell with n-th string of remaining cells tmp = cellfun (@(x) strcmp (str, x), varargin, "uniformoutput", false); + ## check whether all strings of each pair are equal tmp = cellfun (@all, tmp); + ## check whether all pairs are equal bool = all (tmp); else + ## one or no cell at all is always equal to itself bool = true; endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-03-07 18:46:46
|
Revision: 9773 http://octave.svn.sourceforge.net/octave/?rev=9773&view=rev Author: paramaniac Date: 2012-03-07 18:46:36 +0000 (Wed, 07 Mar 2012) Log Message: ----------- control-devel: touch up cat Modified Paths: -------------- trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m Modified: trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m 2012-03-07 18:18:12 UTC (rev 9772) +++ trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m 2012-03-07 18:46:36 UTC (rev 9773) @@ -26,54 +26,78 @@ function dat = cat (dim, varargin) + ## I think this code is pretty elegant because it works for + ## any number of arguments and without a single for-loop :-) + + ## if this overloaded cat method is called, it is guaranteed that + ## * nargin > 0 + ## * at least one argument is an iddata object + if (! is_real_scalar (dim)) + print_usage (); + endif + + ## store all datasets in a single struct 'tmp' tmp = cellfun (@iddata, varargin); [n, p, m, e] = cellfun (@size, varargin, "uniformoutput", false); + ## default values for metadata + ## some of them are overwritten in the switch statement below + expname = tmp(1).expname; + outname = tmp(1).outname; + outunit = tmp(1).outunit; + inname = tmp(1).inname; + inunit = tmp(1).inunit; + switch (dim) - case 1 # vertcat - catenate samples + case 1 # vertcat - catenate samples check_experiments (tmp, e); check_outputs (tmp, p); check_inputs (tmp, m); y = cellfun (@vertcat, tmp.y, "uniformoutput", false); u = cellfun (@vertcat, tmp.u, "uniformoutput", false); + ## note that this also works for time series (u = {}) - case 2 # horzcat - catenate channels + case 2 # horzcat - catenate channels check_experiments (tmp, e); check_samples (n); + y = cellfun (@horzcat, tmp.y, "uniformoutput", false); + u = cellfun (@horzcat, tmp.u, "uniformoutput", false); + outname = vertcat (tmp.outname); outunit = vertcat (tmp.outunit); inname = vertcat (tmp.inname); inunit = vertcat (tmp.inunit); - y = cellfun (@horzcat, tmp.y, "uniformoutput", false); - u = cellfun (@horzcat, tmp.u, "uniformoutput", false); - - case 3 # merge - catenate experiments + case 3 # merge - catenate experiments check_outputs (tmp, p); check_inputs (tmp, m); - - expname = vertcat (tmp.expname); y = vertcat (tmp.y); u = vertcat (tmp.u); - + + expname = vertcat (tmp.expname); + otherwise - error ("iddata: cat: '%s' is an invalid dimension", num2str (dim)); + error ("iddata: cat: '%d' is an invalid dimension", dim); endswitch dat = iddata (y, u); - - %dat.outname = tmp(1).outname; - %dat.outuni + ## copy metadata + dat.expname = expname; + dat.outname = outname; + dat.outunit = outunit; + dat.inname = inname; + dat.inunit = inunit; + endfunction function check_experiments (tmp, e) - if (numel (e) > 1 && ! isequal (e{:})) # isequal doesn't work with less than 2 arguments + if (numel (e) > 1 && ! isequal (e{:})) # isequal doesn't work with less than 2 arguments error ("iddata: cat: number of experiments don't match [%s]", \ num2str (cell2mat (e), "%d ")); endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-03-08 16:01:29
|
Revision: 9782 http://octave.svn.sourceforge.net/octave/?rev=9782&view=rev Author: paramaniac Date: 2012-03-08 16:01:18 +0000 (Thu, 08 Mar 2012) Log Message: ----------- control-devel: add docstring Modified Paths: -------------- trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m Modified: trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m 2012-03-08 14:37:30 UTC (rev 9781) +++ trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m 2012-03-08 16:01:18 UTC (rev 9782) @@ -17,7 +17,51 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {@var{dat} =} cat (@var{dim}, @var{dat1}, @var{dat2}, @dots{}) -## Concatenation of iddata objects along dimension @var{dim}. +## Concatenate iddata sets along dimension @var{dim}. +## +## @strong{Inputs} +## @table @var +## @item dim +## Dimension along which the concatenation takes place. +## @table @var +## @item 1 +## Concatenate samples. +## The samples are concatenated in the following way: +## @code{dat.y@{e@} = [dat1.y@{e@}; dat2.y@{e@}; @dots{}]} +## @code{dat.u@{e@} = [dat1.u@{e@}; dat2.u@{e@}; @dots{}]} +## where @var{e} denotes the experiment. +## The number of experiments, outputs and inputs must be equal for all datasets. +## Equivalent to @command{vertcat}. +## +## @item 2 +## Concatenate inputs and outputs. +## The outputs and inputs are concatenated in the following way: +## @code{dat.y@{e@} = [dat1.y@{e@}, dat2.y@{e@}, @dots{}]} +## @code{dat.u@{e@} = [dat1.u@{e@}, dat2.u@{e@}, @dots{}]} +## where @var{e} denotes the experiment. +## The number of experiments and samples must be equal for all datasets. +## Equivalent to @command{horzcat}. +## +## @item 3 +## Concatenate experiments. +## The experiments are concatenated in the following way: +## @code{dat.y = [dat1.y; dat2.y; @dots{}]} +## @code{dat.u = [dat1.u; dat2.u; @dots{}]} +## The number of outputs and inputs must be equal for all datasets. +## Equivalent to @command{merge}. +## @end table +## +## @item dat1, dat2, @dots{} +## iddata sets to be concatenated. +## @end table +## +## @strong{Outputs} +## @table @var +## @item dat +## iddata set. +## @end table +## +## @seealso{horzcat, merge, vertcat} ## @end deftypefn ## Author: Lukas Reichlin <luk...@gm...> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-06-22 15:16:51
|
Revision: 10670 http://octave.svn.sourceforge.net/octave/?rev=10670&view=rev Author: paramaniac Date: 2012-06-22 15:16:45 +0000 (Fri, 22 Jun 2012) Log Message: ----------- control-devel: handle tsam in cat method Modified Paths: -------------- trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m Modified: trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m 2012-06-22 15:15:16 UTC (rev 10669) +++ trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m 2012-06-22 15:16:45 UTC (rev 10670) @@ -82,7 +82,8 @@ ## store all datasets in a single struct 'tmp' ## tmp is not a valid iddata set anymore, - ## but it doesn't matter, we want just a struct + ## but it doesn't matter, we want just a + ## temporary struct containing all the data tmp = cellfun (@iddata, varargin); [n, p, m, e] = cellfun (@size, varargin, "uniformoutput", false); @@ -91,6 +92,7 @@ ## default values for metadata ## some of them are overwritten in the switch statement below + tsam = tmp(1).tsam; expname = tmp(1).expname; outname = tmp(1).outname; outunit = tmp(1).outunit; @@ -128,13 +130,14 @@ y = vertcat (tmp.y); u = vertcat (tmp.u); + tsam = vertcat (tmp.tsam); expname = vertcat (tmp.expname); otherwise error ("iddata: cat: '%d' is an invalid dimension", dim); endswitch - dat = iddata (y, u); + dat = iddata (y, u, tsam); ## copy metadata dat.expname = expname; @@ -143,7 +146,7 @@ dat.inname = inname; dat.inunit = inunit; - % TODO: handle tsam, w + % TODO: handle w endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |