sFunction for matrix calculation of matrices with different ranges
Show older comments
Hey all!
I am looking for a Level 2 MATLAB sFunction for Simulink which can handle matrices with different ranges.
What I tried is:
function anregung(block)
% Level-2 MATLAB file S-Function for times two demo.
% Copyright 1990-2009 The MathWorks, Inc.
% $Revision: 1.1.6.2 $
setup(block);
%endfunction
function setup(block)
%%Register number of input and output ports
block.NumInputPorts = 3;
block.NumOutputPorts = 1;
%%Setup functional port properties to dynamically
%%inherited.
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
block.InputPort(1).DirectFeedthrough = true;
block.InputPort(2).DirectFeedthrough = true;
block.InputPort(3).DirectFeedthrough = true;
%%Set up the inport data-type properties.
block.InputPort(1).DatatypeID = -1;
block.InputPort(1).Complexity = 'Real';
%%Set up the outport data-type properties.
block.OutputPort(1).DatatypeID = -1;
block.OutputPort(1).Complexity = 'Real';
%%Set block sample time to inherited
block.SampleTimes = [0 0];
%%Set the block simStateCompliance to default (i.e., same as a built-in block)
block.SimStateCompliance = 'DefaultSimState';
%%Run accelerator on TLC - Eine TLC Datei wird im Falle von 'true' erzeugt
block.SetAccelRunOnTLC(true);
%%Set the number of Parameters
block.NumDialogPrms = 3;
%%Register methods
block.RegBlockMethod('Outputs', @Output);
block.RegBlockMethod('SetInputPortDimensions', @SetInpPortDims);
block.RegBlockMethod('SetOutputPortDimensions', @SetOutPortDims);
%endfunction
function Output(block)
M_kappa = block.DialogPrm(1).Data;
R_kappa = block.DialogPrm(2).Data;
h_delta = block.DialogPrm(3).Data;
block.OutputPort(1).Data = (M_kappa\R_kappa)*h_delta;
%endfunction
M_kappa is a 3x3 Matrix, R_kappa 3x2 and h_delta is a 2x1 vector. As you can see, I'd just like to devide the matrices and multiplicate them with the vector.
The point is, I get three errors:
- Item one 'Error in port widths or dimensions. Output port 1 of 'modele/Constant1' is a [3x2] matrix.'
- Item two 'Error evaluating registered method 'SetInputPortDimensions' of MATLAB S-Function 'anregung' in 'model/Level-2 MATLAB S-Function'. The dimensions of output port 1 of 'model/Level-2 MATLAB S-Function' cannot be changed from [3x3] to [3x2]. The following is the MATLAB call stack (file names and line numbers) that produced this error: ['C:...path\Simulink\anregung.m'] [92]'
- Item three 'The dimensions of output port 1 of 'model/Level-2 MATLAB S-Function' cannot be changed from [3x3] to [3x2].'
Anybody an idea how to define the input dimensions properly?
Many thanks in advance!
Greeeetz Drej
7 Comments
Kaustubha Govind
on 26 Sep 2013
How do you define SetInpPortDims and SetOutPortDims?
Andreas
on 27 Sep 2013
Kaustubha Govind
on 27 Sep 2013
I am confused by your implementation of SetInpPortDims and SetOutPortDims. Which input's dimensions does the output port dimension match with exactly? You seem to overwriting block.OutputPort(1).Dimensions for all values of idx. Also, why force block.InputPort(1).Dimensions to be the same as the output port dimensions?
Andreas
on 27 Sep 2013
Answers (0)
Categories
Find more on User-Defined Functions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!