Mercurial > hg > ltpda
comparison m-toolbox/classes/@ssm/getMatrixSelection.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 % GETMATRIXSELECTIONS allows to select data in a block-defined matrix | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: GETMATRIXSELECTIONS allows to select data in a | |
5 % block-defined matrix with user i/o selection, and i/o data selection. | |
6 % Permuations matrices are returned | |
7 % | |
8 % CALL: [ao_out pl_out] = getModelMatrixSelection(sys, plist_inputs) | |
9 % | |
10 % INPUTS: | |
11 % | |
12 % OUTPUTS: | |
13 % | |
14 % <a href="matlab:utils.helper.displayMethodInfo('ssm', 'getModelMatrixSelection')">Parameters Description</a> | |
15 % | |
16 % VERSION: $Id: getMatrixSelection.m,v 1.5 2011/04/08 08:56:23 hewitson Exp $ | |
17 % | |
18 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
19 | |
20 function varargout = getMatrixSelection(blockMat, oldColumns, newColumns, oldRows, newRows) | |
21 error('This function is deprecated, it will be modified or removed. Use double instead.') | |
22 utils.helper.msg(utils.const.msg.MNAME, ['running ', mfilename]); | |
23 | |
24 %% making indexes out of i/o data | |
25 indexInputsIn = makePortIndex( oldColumns, newColumns ); | |
26 colSizesIn = getsizes(indexInputsIn); | |
27 colSizes = oldColumns.Nports; | |
28 | |
29 indexOutputsOut = makePortIndex( oldRows, newRows ); | |
30 rowSizesOut = getsizes(indexOutputsOut); | |
31 rowSizes = oldRows.Nports; | |
32 | |
33 %% pruning ssmBlocks | |
34 inputNamesFull = getcellstr(oldColumns, colSizes); | |
35 inputsIn = blocksPrune(oldColumns, indexInputsIn); | |
36 inputNames = getcellstr(inputsIn, colSizesIn); | |
37 inputUnits = getUnit(inputsIn, colSizesIn); | |
38 | |
39 outputNamesFull = getcellstr(oldRows, rowSizes); | |
40 outputsOut = blocksPrune(oldRows, indexOutputsOut); | |
41 outputNames = getcellstr(outputsOut, rowSizesOut); | |
42 outputUnits = getUnit(outputsOut, rowSizesOut); | |
43 | |
44 %% pruning matrix and turning it to a double | |
45 A = ssm.blockMatFusion( blockMat, rowSizes, colSizes); | |
46 | |
47 %% finding input and output variable positions of data in option plists | |
48 | |
49 if ischar(newColumns) && strcmp(newColumns, 'ALL') %case 'ALL' 'NONE' | |
50 inputsConv = eye(sum(colSizes),sum(colSizes)); | |
51 elseif ischar(newColumns) && strcmp(newColumns, 'NONE') %case 'NONE' | |
52 inputsConv = eye(sum(colSizes),0); | |
53 else | |
54 if ischar(newColumns) | |
55 newColumns = {newColumns}; | |
56 end | |
57 NinputsIn = numel(newColumns); | |
58 Ninputs = sum(colSizes); | |
59 inputsConv = zeros(Ninputs,NinputsIn); | |
60 for i=1:NinputsIn | |
61 position = reshape( strcmpi(inputNamesFull, newColumns{i}) , [Ninputs, 1]); | |
62 inputsConv(:,i) = double(position).'; | |
63 if sum(position)==0 | |
64 error(['No variable found named ', newColumns{i}]); | |
65 end | |
66 end | |
67 end | |
68 | |
69 %% finding input and output variable positions of data in option plists | |
70 | |
71 if ischar(newRows) && strcmp(newRows, 'ALL') %case 'ALL' 'NONE' | |
72 outputsConv = eye(sum(rowSizes),sum(rowSizes)); | |
73 elseif ischar(newRows) && strcmp(newRows, 'NONE') %case 'NONE' | |
74 outputsConv = eye(0,sum(rowSizes)); | |
75 else | |
76 if ischar(newRows) | |
77 newRows = {newRows}; | |
78 end | |
79 NoutputsOut = numel(newRows); | |
80 Noutputs = sum(rowSizes); | |
81 outputsConv = zeros(NoutputsOut,Noutputs); | |
82 for i=1:NoutputsOut | |
83 position = reshape( strcmpi(newRows{i}, outputNamesFull ) , [1, Noutputs]); | |
84 outputsConv(i,:) = double(position); | |
85 if sum(position)==0 | |
86 error(['No variable found named ', newRows{i}]); | |
87 end | |
88 end | |
89 end | |
90 | |
91 %% parsing output matrices | |
92 varargout = {A, inputsConv, outputsConv, inputNames, outputNames, inputUnits, outputUnits}; | |
93 end | |
94 | |
95 function sizes = getsizes(idx) | |
96 sizes = zeros(1, numel(idx)); | |
97 for i=1:numel(idx) | |
98 sizes(i) = sum(idx{i}); | |
99 end | |
100 end | |
101 | |
102 function names = getcellstr(block, sizes) | |
103 names = cell(1, sum(sizes)); | |
104 k = 1; | |
105 for i=1:numel(block) | |
106 for j=1:sizes(i) | |
107 names{k} = block(i).ports(j).name; | |
108 k = k+1; | |
109 end | |
110 end | |
111 end | |
112 | |
113 function units = getUnit(block, sizes) | |
114 units = unit.initObjectWithSize(1, sum(sizes)); | |
115 k = 1; | |
116 for i=1:numel(block) | |
117 for j=1:sizes(i) | |
118 units(k) = block(i).ports(j).units; | |
119 k = k+1; | |
120 end | |
121 end | |
122 end | |
123 | |
124 |