Mercurial > forge
changeset 9457:1614cd3d4080 octave-forge
control-devel: add subsref method to iddata class
author | paramaniac |
---|---|
date | Tue, 21 Feb 2012 20:38:43 +0000 |
parents | 5b575a06d7b8 |
children | e823bd67d070 |
files | extra/control-devel/inst/@iddata/__property_names__.m extra/control-devel/inst/@iddata/display.m extra/control-devel/inst/@iddata/get.m extra/control-devel/inst/@iddata/iddata.m extra/control-devel/inst/@iddata/set.m extra/control-devel/inst/@iddata/subsref.m |
diffstat | 6 files changed, 83 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/extra/control-devel/inst/@iddata/__property_names__.m Tue Feb 21 19:27:53 2012 +0000 +++ b/extra/control-devel/inst/@iddata/__property_names__.m Tue Feb 21 20:38:43 2012 +0000 @@ -35,7 +35,7 @@ "inunit"; "tsam"; "timeunit"; - "exname"; + "expname"; "name"; "notes"; "userdata"};
--- a/extra/control-devel/inst/@iddata/display.m Tue Feb 21 19:27:53 2012 +0000 +++ b/extra/control-devel/inst/@iddata/display.m Tue Feb 21 20:38:43 2012 +0000 @@ -27,7 +27,7 @@ datname = inputname (1); [outname, p] = __labels__ (dat.outname, "y"); [inname, m] = __labels__ (dat.inname, "u"); - [exname, e] = __labels__ (dat.exname, "exp"); + [expname, e] = __labels__ (dat.expname, "exp"); [n, p, m, e] = size (dat); @@ -40,7 +40,7 @@ disp (str); disp (""); - disp (__col2str__ (exname, "Experiment")); + disp (__col2str__ (expname, "Experiment")); disp (""); disp (__col2str__ (outname, "Outputs")); disp (""); @@ -48,7 +48,7 @@ disp (""); %{ - str = strjust (strvcat (exname), "left"); + str = strjust (strvcat (expname), "left"); space = (repmat (" ", e, 1)); str = [space, str]; %}
--- a/extra/control-devel/inst/@iddata/get.m Tue Feb 21 19:27:53 2012 +0000 +++ b/extra/control-devel/inst/@iddata/get.m Tue Feb 21 20:38:43 2012 +0000 @@ -54,8 +54,8 @@ val = dat.tsam; case {"timeunit"} val = dat.timeunit - case {"exname", "experimentname"} - val = dat.exname; + case {"expname", "experimentname"} + val = dat.expname; case "name" val = dat.name; case "notes"
--- a/extra/control-devel/inst/@iddata/iddata.m Tue Feb 21 19:27:53 2012 +0000 +++ b/extra/control-devel/inst/@iddata/iddata.m Tue Feb 21 20:38:43 2012 +0000 @@ -75,12 +75,12 @@ outname = repmat ({""}, p, 1); inname = repmat ({""}, m, 1); - exname = repmat ({""}, e, 1); + expname = repmat ({""}, e, 1); dat = struct ("y", {y}, "outname", {outname}, "outunit", {outname}, "u", {u}, "inname", {inname}, "inunit", {inname}, "tsam", tsam, "timeunit", {""}, - "exname", {exname}, + "expname", {expname}, "name", "", "notes", {{}}, "userdata", []); dat = class (dat, "iddata");
--- a/extra/control-devel/inst/@iddata/set.m Tue Feb 21 19:27:53 2012 +0000 +++ b/extra/control-devel/inst/@iddata/set.m Tue Feb 21 20:38:43 2012 +0000 @@ -79,8 +79,8 @@ dat.tsam; case {"timeunit"} dat.timeunit - case {"exname", "experimentname"} - dat.exname = __adjust_labels__ (val, e); + case {"expname", "experimentname"} + dat.expname = __adjust_labels__ (val, e); case {"tsam", "ts"} if (issample (val, -1))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/control-devel/inst/@iddata/subsref.m Tue Feb 21 20:38:43 2012 +0000 @@ -0,0 +1,73 @@ +## 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 -*- +## Subscripted reference for LTI objects. +## Used by Octave for "sys = sys(2:4, :)" or "val = sys.prop". + +## Author: Lukas Reichlin <lukas.reichlin@gmail.com> +## Created: February 2012 +## Version: 0.1 + +function a = subsref (a, s) + + if (isempty (s)) + error ("iddata: subsref: missing index"); + endif + + for k = 1 : numel (s) + if (isa (a, "iddata")) + switch (s(k).type) + case "()" + idx = s(k).subs; + if (numel (idx) > 4) + error ("iddata: subsref: need four or less indices"); + else + a = __dat_prune__ (a, idx{:}); + endif + case "." + fld = s(k).subs; + a = get (a, fld); + otherwise + error ("iddata: subsref: invalid subscript type"); + endswitch + else # not an iddata set + a = subsref (a, s(k:end)); + return; + endif + endfor + +endfunction + + +function dat = __dat_prune__ (dat, spl_idx = ":", out_idx = ":", in_idx = ":", exp_idx = ":") + + dat.y = dat.y(exp_idx); + dat.y = cellfun (@(y) y(spl_idx, out_idx), dat.y, "uniformoutput", false); + dat.outname = dat.outname(out_idx); + dat.outunit = dat.outunit(out_idx); + + if (! isempty (dat.u)) + dat.u = dat.u(exp_idx); + dat.u = cellfun (@(u) u(spl_idx, in_idx), dat.u, "uniformoutput", false); + dat.inname = dat.inname(in_idx); + dat.inunit = dat.inunit(in_idx); + endif + + dat.expname = dat.expname(exp_idx); + +endfunction \ No newline at end of file