Mercurial > hg > ltpda
comparison m-toolbox/classes/@pzmodel/rdivide.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % RDIVIDE overloads the division operator for pzmodels. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: RDIVIDE overloads the division operator for pzmodels. | |
5 % | |
6 % CALL: pzm = rdivide(pzm1, pzm2); | |
7 % pzm = pzm1./pzm2; | |
8 % | |
9 % <a href="matlab:utils.helper.displayMethodInfo('pzmodel', 'rdivide')">Parameters Description</a> | |
10 % | |
11 % VERSION: $Id: rdivide.m,v 1.11 2011/04/08 08:56:32 hewitson Exp $ | |
12 % | |
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
14 | |
15 function varargout = rdivide(varargin) | |
16 | |
17 %%% Check if this is a call for parameters | |
18 if utils.helper.isinfocall(varargin{:}) | |
19 varargout{1} = getInfo(varargin{3}); | |
20 return | |
21 end | |
22 | |
23 %%% Input objects checks | |
24 if nargin < 1 | |
25 error('### incorrect number of inputs.') | |
26 end | |
27 | |
28 % Collect input pzmodels, plists and input variable names | |
29 in_names = cell(size(varargin)); | |
30 for ii = 1:nargin | |
31 in_names{end+1} = inputname(ii); | |
32 end | |
33 args = utils.helper.collect_values(varargin); | |
34 [pzms, invars, rest] = utils.helper.collect_objects(args, 'pzmodel', in_names); | |
35 pl = utils.helper.collect_objects(args, 'plist'); | |
36 | |
37 % Combine with default plist | |
38 pl = combine(pl, getDefaultPlist('Default')); | |
39 | |
40 % Decide on a deep copy or a modify | |
41 cpzms = copy(pzms, nargout); | |
42 | |
43 % Loop over pzmodels and modify the first | |
44 pzmout = cpzms(1); | |
45 hists = pzmout.hist; | |
46 name = pzmout.name; | |
47 for pp=2:numel(cpzms) | |
48 | |
49 % process this pzmodel | |
50 pzm = cpzms(pp); | |
51 | |
52 % Combine the poles and zeros | |
53 pzmout.poles = [pzmout.poles pzm.zeros]; | |
54 pzmout.zeros = [pzmout.zeros pzm.poles]; | |
55 pzmout.gain = pzmout.gain ./ pzm.gain; | |
56 pzmout.delay = pzmout.delay - pzm.delay; | |
57 | |
58 % Multiply the units | |
59 if ~isempty(pzm.iunits.strs) && ~isempty(pzmout.ounits.strs) | |
60 if pzmout.ounits ~= pzm.ounits | |
61 error('### Output units of model %s %s must match the output units of model %s %s', ... | |
62 pzm.name, char(pzm.ounits), pzmout.name, char(pzmout.ounits)); | |
63 end | |
64 end | |
65 if ~isempty(pzm.ounits.strs) | |
66 pzmout.ounits = pzm.iunits; | |
67 end | |
68 if isempty(pzmout.iunits.strs) | |
69 pzmout.iunits = pzm.ounits; | |
70 end | |
71 | |
72 % compute the new name | |
73 name = ['(' name './' pzm.name ')']; | |
74 | |
75 hists = [hists pzm.hist]; | |
76 | |
77 end | |
78 | |
79 % set name | |
80 pzmout.name = name; | |
81 % Add history | |
82 pzmout.addHistory(getInfo('None'), pl, invars, hists); | |
83 | |
84 % Outputs | |
85 varargout{1} = pzmout; | |
86 | |
87 end | |
88 | |
89 | |
90 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
91 % Local Functions % | |
92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
93 | |
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
95 % | |
96 % FUNCTION: getInfo | |
97 % | |
98 % DESCRIPTION: Get Info Object | |
99 % | |
100 % HISTORY: 11-07-07 M Hewitson | |
101 % Creation. | |
102 % | |
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
104 | |
105 function ii = getInfo(varargin) | |
106 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
107 sets = {}; | |
108 pls = []; | |
109 elseif nargin == 1&& ~isempty(varargin{1}) && ischar(varargin{1}) | |
110 sets{1} = varargin{1}; | |
111 pls = getDefaultPlist(sets{1}); | |
112 else | |
113 sets = {'Default'}; | |
114 pls = []; | |
115 for kk=1:numel(sets) | |
116 pls = [pls getDefaultPlist(sets{kk})]; | |
117 end | |
118 end | |
119 % Build info object | |
120 ii = minfo(mfilename, 'pzmodel', 'ltpda', utils.const.categories.aop, '$Id: rdivide.m,v 1.11 2011/04/08 08:56:32 hewitson Exp $', sets, pls); | |
121 ii.setModifier(false); | |
122 end | |
123 | |
124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
125 % | |
126 % FUNCTION: getDefaultPlist | |
127 % | |
128 % DESCRIPTION: Get Default Plist | |
129 % | |
130 % HISTORY: 11-07-07 M Hewitson | |
131 % Creation. | |
132 % | |
133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
134 | |
135 function plout = getDefaultPlist(set) | |
136 persistent pl; | |
137 persistent lastset; | |
138 if exist('pl', 'var')==0 || isempty(pl) || ~strcmp(lastset, set) | |
139 pl = buildplist(set); | |
140 lastset = set; | |
141 end | |
142 plout = pl; | |
143 end | |
144 | |
145 function plo = buildplist(set) | |
146 switch lower(set) | |
147 case 'default' | |
148 plo = plist.EMPTY_PLIST; | |
149 otherwise | |
150 plo = plist.EMPTY_PLIST; | |
151 end | |
152 end | |
153 |