inherit dimension of multiple input port in a Level-2 S-Function

1 次查看(过去 30 天)
I'm using a QP solver (qpas.mex) in Simulink that requires a Level-2 S-Function block. However, I have trouble to specify the dimension of each input port. Here is the setup
function mySFcn(block)
setup(block);
function setup(block)
nInPorts = 2;
block.NumInputPorts = nInPorts;
block.NumOutputPorts = 1;
for i = 1 : nInPorts
block.InputPort(i).Dimensions = -1;
block.InputPort(i).DatatypeID = 0; % double
block.InputPort(i).Complexity = 'Inherited';
block.InputPort(i).DirectFeedthrough = true;
block.InputPort(i).SamplingMode = 'Inherited';
end
block.OutputPort(1).Dimensions = -1;
block.OutputPort(1).DatatypeID = 0; % double
block.OutputPort(1).Complexity = 'Inherited';
block.NumDialogPrms = 0;
block.SampleTimes = [-1 0];
block.SimStateCompliance = 'DefaultSimState';
block.RegBlockMethod('Outputs', @Outputs); % Required
block.RegBlockMethod('Terminate', @Terminate); % Required
function Outputs(block)
W = block.InputPort(1).Data; % 12 x 12, e.g.
tau = block.InputPort(2).Data; % 3 x 1, e.g.
block.OutputPort(1).Data = qpas(W,tau); % e.g.
function Terminate(block)
I always get an error message that states a 12x12 matrix cannot get into my s-function block through port 1. Anybody know how to correct this error? By the way, each port will have different dimension, and I have no way to know the dimension.
  1 个评论
Mike Quan
Mike Quan 2017-5-5
Hello Mr Quan,
I have a similiar problem, where the dimension of the biggest input matrix somehow determines the dimensions for any other inut AND output.
Also I tried making input/output sizing inherited by
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
without success! Please tell, if you find a solution!

请先登录,再进行评论。

回答(1 个)

Ridouane OULHIQ
Ridouane OULHIQ 2020-10-29
Just don't set the dimension

类别

Help CenterFile Exchange 中查找有关 Event Functions 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by