sFunction for matrix calculation of matrices with different ranges
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre Configure Block Features for MATLAB S-Functions en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!