comparison m-toolbox/m/gui/gltpda/g_arrmult.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 function g_arrmult(block)
2
3 % This is the automatic function wrapper
4 % ========================================================================
5 % ==================== level-2 M file S-function =========================
6 % ========================================================================
7 % This wrapper is the automatic function, called by every function block
8 % in Simulink, able to execute m-file functions retrieving from Simulink:
9 % (1) the pointer to the AO(s) to be analyzed, coming in as input of the
10 % corresponding block (ie, the DATA),
11 % (2) the name of the function to be applied on those data, from the tag
12 % of the currently executed block (ie, the true FUNCTION),
13 % (3) the parameters for that particular block, retrieved from the global
14 % shared workspace by the handle of the block (ie, the PARAMETERS).
15 %
16 % The output is then generated as:
17 % OUTPUT = FUNCTION(DATA,PARAMETERS)
18 %
19 % This output in the end is saved into the global array containing all
20 % the AOs (ie, all the DATA go together with other data): thus this output
21 % will be freely accessible by all the other functions.
22 %
23 % The only real output to Simulink will be just the ordinal number of the
24 % so-generated AO into the global array of AOs.
25 %
26 % =======================================================================
27 % For UNIVARIATE analysis functions
28 % =======================================================================
29 % (the difference with the other function, 'ltpdasimmulti', is the
30 % dimension of the output port, here set = DimInputPorts)
31 %
32 %
33 % $Id: g_arrmult.m,v 1.1 2008/03/01 13:43:20 nicola Exp $
34
35 setup(block);
36
37 %%
38 function setup(block)
39 % global LTPDAinvar loopstatus
40
41
42 %% Register dialog parameter: none, because they're retrieved directly
43 %% from the memory. This will prevent the user to modify the parameters
44 %% outside the proper parameters panel:
45 block.NumDialogPrms = 0;
46
47 %% Register number of input and output ports
48 block.NumInputPorts = 1;
49 block.NumOutputPorts = 1;
50
51 %% Setup functional port properties to dynamically inherited.
52 block.SetPreCompInpPortInfoToDynamic;
53 block.SetPreCompOutPortInfoToDynamic;
54
55 block.InputPort(1).DirectFeedthrough = true;
56 block.InputPort(1).DatatypeID = 0;
57 block.InputPort(1).Complexity = 0;
58 block.OutputPort(1).DatatypeID = 0;
59 block.OutputPort(1).Complexity = 0;
60 block.OutputPort(1).Dimensions = 1;
61 %(block.InputPort(1).Dimensions)^2;
62 block.SampleTimes = [0 0];
63 block.SetAccelRunOnTLC(false);
64
65 %% Register methods
66 block.RegBlockMethod('SetInputPortSamplingMode',@SetInpPortFrameData);
67 block.RegBlockMethod('SetInputPortDimensions', @SetInpPortDims);
68 % block.RegBlockMethod('SetOutputPortDimensions', @SetOutPortDims);
69 block.RegBlockMethod('Outputs', @Outputs);
70
71 function SetInpPortFrameData(block, idx, fd)
72 block.InputPort(1).SamplingMode = fd;
73 block.OutputPort(1).SamplingMode = fd;
74
75 function SetInpPortDims(block, idx, di)
76 block.InputPort(idx).Dimensions = di;
77 % outdims=(block.InputPort(1).Dimensions)^2;
78 % block.OutputPort(1).Dimensions = outdims;
79
80 % function SetOutPortDims(block, idx, di)
81 % block.OutputPort(idx).Dimensions = 1;
82
83
84 %%
85 function Outputs(block)
86 global LTPDAinvar
87
88 if length(block.InputPort(1).Data)~=2
89 block.OutputPort(1).Data = block.InputPort(1).Data;
90 disp('========================================================')
91 disp('Something''s wrong. Please check ltpdaarrmult.m function')
92 disp('========================================================')
93 return
94 end
95
96 outdata = LTPDAinvar{block.InputPort(1).Data(1)} .* LTPDAinvar{block.InputPort(1).Data(2)};
97 outdata = num2cell(outdata);
98
99 lineHandles = get_param(get_param(gcbh,'Parent'),'LineHandles');
100 signalName = get(lineHandles.Outport,'Name');
101 if ~isempty(signalName) && numel(outdata)==1
102 outdata{1} = setnh(outdata{1},'name',signalName);
103 end
104 xx = size(LTPDAinvar,1);
105 LTPDAinvar(xx+1,:) = [outdata,0];
106 block.OutputPort(1).Data = xx+1;
107
108 %endfunction