Variable size output in level-2 matlab S-functions

Hello,
I am trying to write a level-2 matlab S-function with a variable sized output. However, unlike official examples and documentation the size of the ouput is not dependent on the input or parameters. I am struggling to create this as the error dialogue box is unhelpful.
I would really appreciate any help that can be provided to solve this issue. A minimum example of the code is
function myFunc(block)
setup(block);
%endfunction
%%Function: setup ===================================================
function setup(block)
% Register number of ports
block.NumInputPorts = 1;
block.NumOutputPorts = 2;
% Setup port properties to be inherited or dynamic
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
% Override input port properties
block.InputPort(1).Dimensions = 1;
block.InputPort(1).DatatypeID = 0; % double
block.InputPort(1).Complexity = 'Real';
block.InputPort(1).DirectFeedthrough = false;
% Override output port properties
block.OutputPort(1).DimensionsMode = 'Variable';
block.OutputPort(1).Dimensions = 1; %'Variable';
block.OutputPort(1).DatatypeID = 0; % double
block.OutputPort(1).Complexity = 'Real';
block.OutputPort(1).SamplingMode = 'Sample';
block.OutputPort(2).DimensionsMode = 'Variable';
block.OutputPort(2).Dimensions = 1; %'Variable';
block.OutputPort(2).DatatypeID = 0; % double
block.OutputPort(2).Complexity = 'Real';
block.OutputPort(2).SamplingMode = 'Sample';
% Register parameters
block.NumDialogPrms = 0;
block.SampleTimes = [-1 0];
% SetInputPortSamplingMode:
block.RegBlockMethod('SetInputPortSamplingMode', @SetInpPortFrameData);
block.SimStateCompliance = 'DefaultSimState';
block.RegBlockMethod('InitializeConditions', @InitializeConditions);
block.RegBlockMethod('Start', @Start);
block.RegBlockMethod('Outputs', @Outputs); % Required
block.RegBlockMethod('Terminate', @Terminate); % Required
%end setup
function InitializeConditions(block)
%%INITIALIZE INDICES AS DOUBLE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%here I initialize some parameters that are used during the algorithm
% for e.g.
a = 1;
b = 2;
% etc.
%end InitializeConditions
function Outputs(block)
xi = block.InputPort(1).Data;
% run some logic here with xi, a, b, etc.
% obtain two matrices
% A of size (integer X 2)
% b of size (integer X 1)
% assign outputs
[rowCount_A, colCount_A] = size(A);
block.OutputPort(1).CurrentDimensions = [rowCount_A, colCount_A];
block.OutputPort(1).Data = A;
[rowCount_b, colCount_b] = size(b);
block.OutputPort(2).CurrentDimensions = [rowCount_b, colCount_b];
block.OutputPort(2).Data = b;
%end Outputs
%%Set the sampling of the input ports
function SetInpPortFrameData(block, idx, fd)
block.InputPort(idx).SamplingMode = fd;
for ii = 1:block.NumOutputPorts
block.OutputPort(ii).SamplingMode = fd;
end
% end SetInpPortFrameData
% Set the dimension of the output ports
function setOutputVarDims(block, opIdx, inputIdx, rowCount_A, colCount_A, rowCount_b, colCount_b)
% Set current (run-time) dimensions of the output
block.OutputPort(1).CurrentDimensions = [rowCount_A, colCount_A];
block.OutputPort(2).CurrentDimensions = [rowCount_b, colCount_b];
% end setOutputVarDims
function Terminate(block)
%end Terminate
Thank you!
Regards!...

1 个评论

Is there any answer for this problem I am struggling with the same problem.
Thanks for help

请先登录,再进行评论。

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by