Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[b109d7]: inst / @iddata / subsref.m Maximize Restore History

Download this file

subsref.m    103 lines (78 with data), 2.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
## Copyright (C) 2012, 2013 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 iddata objects.
## Used by Octave for "dat = dat(2:4, :)" or "val = dat.prop".
## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
## Created: February 2012
## Version: 0.3
function a = subsref (a, s)
if (numel (s) == 0)
return;
endif
switch (s(1).type)
case "()"
idx = s(1).subs;
if (numel (idx) > 4)
error ("iddata: subsref: need four or less indices");
else
a = __dat_prune__ (a, idx{:});
endif
case "."
fld = s(1).subs;
a = get (a, fld);
otherwise
error ("iddata: subsref: invalid subscript type");
endswitch
a = subsref (a, s(2:end));
endfunction
function dat = __dat_prune__ (dat, spl_idx = ":", out_idx = ":", in_idx = ":", exp_idx = ":")
out_idx = __handle_idx__ (dat.outname, out_idx, "outname");
in_idx = __handle_idx__ (dat.inname, in_idx, "inname");
exp_idx = __handle_idx__ (dat.expname, exp_idx, "expname");
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);
dat.tsam = dat.tsam(exp_idx);
endfunction
function idx = __handle_idx__ (name, idx, id)
if (ischar (idx) && ! strcmp (idx, ":"))
idx = {idx};
endif
if (iscell (idx))
idx = cellfun (@(x) __str2idx__ (name, x, id), idx);
endif
endfunction
function idx = __str2idx__ (name, str, id)
tmp = strcmp (name, str)(:);
switch (nnz (tmp))
case 1
idx = find (tmp);
case 0
error ("iddata: %s '%s' not found", id, str);
otherwise
error ("iddata: %s '%s' is ambiguous", id, str);
endswitch
endfunction