필터 지우기
필터 지우기

sFunction for matrix calculation of matrices with different ranges

조회 수: 1 (최근 30일)
Andreas
Andreas 2013년 9월 26일
댓글: Andreas 2013년 9월 27일
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:
  1. Item one 'Error in port widths or dimensions. Output port 1 of 'modele/Constant1' is a [3x2] matrix.'
  2. 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]'
  3. 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
Andreas
Andreas 2013년 9월 27일
편집: Andreas 2013년 9월 27일
In case I delete the function SetInpPortDims(s,idx,di) and set the
block.InputPort('every port').DirectFeedthrough
to true, I get the error, that the outport of the 'Constant'-R_kappa, which is a [3x2] matrix does not correspond to the input port 2 of the sfunction, because it is a [3x3] matrix.
to clarify ma problem I added an image of my simple model and in addition the entire code.
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 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('PostPropagationSetup', @DoPostPropSetup);
block.RegBlockMethod('Outputs', @Output);
function SetInpPortDims(s, port, di)
% Set dimension mode
block.InputPort(port).Dimensions = di;
%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
Andreas
Andreas 2013년 9월 27일
편집: Andreas 2013년 9월 30일
No other suggestions?

댓글을 달려면 로그인하십시오.

답변 (0개)

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by