comparison m-toolbox/classes/@ssm/removeEmptyBlocks.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 % REMOVEEMPTYBLOCKS enables to do model simplification
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 %
5 % DESCRIPTION: REMOVEEMPTYBLOCKS allows you to eliminate input/state/output variables.
6 %
7 % CALL: [ssm] = REMOVEEMPTYBLOCKS(ssm, pl);
8 %
9 % INPUTS :
10 % ssm - a ssm object
11 % pl - an option plist
12 %
13 % OPTIONS :
14 % plist with parameters 'inputs', 'states' and 'outputs' to indicate which
15 % inputs, states and outputs variables are taken in account. This requires
16 % proper variable naming. If a variable called appears more that once it
17 % will be used once only.
18 %
19 % OUTPUTS:
20 % The output array are of size Nsys*Noptions
21 % sys_out - (array of) ssm objects without the specified information
22 %
23 %
24 % <a href="matlab:utils.helper.displayMethodInfo('ssm', 'removeEmptyBlocks')">Parameters Description</a>
25 %
26 % VERSION: $Id: removeEmptyBlocks.m,v 1.2 2011/07/29 13:46:09 ferran Exp $
27 %
28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29
30 function varargout = removeEmptyBlocks(varargin)
31
32 import utils.const.*
33 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
34 %% starting initial checks
35
36 % Check if this is a call for parameters
37 if utils.helper.isinfocall(varargin{:})
38 varargout{1} = getInfo(varargin{3});
39 return
40 end
41
42 % Collect input variable names
43 in_names = cell(size(varargin));
44 for ii = 1:nargin,in_names{ii} = inputname(ii);end
45
46 % Collect all SSMs and plists
47 [sys, ssm_invars, rest] = utils.helper.collect_objects(varargin(:), 'ssm', in_names);
48 [pl, invars2, rest] = utils.helper.collect_objects(rest(:), 'plist');
49 if ~isempty(rest)
50 pl = combine(pl, plist(rest{:}));
51 end
52 pl = combine(pl, getDefaultPlist);
53
54 Nsys = numel(sys);
55 if Nsys ~= 1
56 error('### Please input (only) one SSM model');
57 end
58
59 % Decide on a deep copy or a modify, depending on the output
60 sys = copy(sys, nargout);
61
62 %% begin function body
63
64 % Loop over input systems
65 for i_sys=1:Nsys
66 %% retrieving system data
67 inputSizes = sys(i_sys).inputsizes;
68 statesSizes = sys(i_sys).statesizes;
69 outputSizes = sys(i_sys).outputsizes;
70 keepInputs = inputSizes>0;
71 keepStates = statesSizes>0;
72 keepOutputs = outputSizes>0;
73 %% selecting data
74 sys.amats = sys.amats(keepStates, keepStates);
75 sys.bmats = sys.bmats(keepStates, keepInputs);
76 sys.cmats = sys.cmats(keepOutputs, keepStates);
77 sys.dmats = sys.dmats(keepOutputs, keepInputs);
78 sys.inputs = sys.inputs(keepInputs);
79 sys.states = sys.states(keepStates);
80 sys.outputs = sys.outputs(keepOutputs);
81 %% updating size fields
82 sys(i_sys).addHistory(ssm.getInfo(mfilename), pl , ssm_invars(i_sys), sys(i_sys).hist );
83 %% checking system has some inputs and outputs left
84 if sys(i_sys).Ninputs == 0
85 error('The ssm object has no inputs, which is not allowed!')
86 elseif sys(i_sys).Noutputs == 0
87 error('The ssm object has no outputs, which is not allowed!')
88 end
89 end
90
91 if nargout == numel(sys)
92 for ii = 1:numel(sys)
93 varargout{ii} = sys(ii);
94 end
95 else
96 varargout{1} = sys;
97 end
98 end
99
100
101 %--------------------------------------------------------------------------
102 % Get Info Object
103 %--------------------------------------------------------------------------
104 function ii = getInfo(varargin)
105
106 if nargin == 1 && strcmpi(varargin{1}, 'None')
107 sets = {};
108 pl = [];
109 else
110 sets = {'Default'};
111 pl = getDefaultPlist;
112 end
113 % Build info object
114 ii = minfo(mfilename, 'ssm', 'ltpda', utils.const.categories.op, '$Id: removeEmptyBlocks.m,v 1.2 2011/07/29 13:46:09 ferran Exp $', sets, pl);
115 end
116
117 %--------------------------------------------------------------------------
118 % Get Default Plist
119 %--------------------------------------------------------------------------
120 function pl = getDefaultPlist()
121 pl = plist();
122
123 end
124