|
I have a very simple simulink model which uses S-function to output a 2x2 matrix to display block. The matrix is initialized in matlab workspace, and it is input to the s-function through dialog parameter. The input to this s-function block is just the constant block with value of 1. It gives me an error message "Error in 'SetOutputPortDimensions' method of ...... The dimensions of output port 0 should have been set to [1], but was instead set to [2x2]"
I tried many different ways, but I cant get this to work. Thanks.
My code is below:
function test4(block)
setup(block);
function setup(block)
block.NumInputPorts = 1;
block.NumOutputPorts = 1;
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
block.InputPort(1).DatatypeID = 0; % double
block.InputPort(1).Complexity = 'Real';
block.OutputPort(1).DatatypeID = 0; % double
block.OutputPort(1).Complexity = 'Real';
block.NumDialogPrms = 1;
block.SampleTimes = [-1 0];
block.SimStateCompliance = 'DefaultSimState';
block.RegBlockMethod('SetInputPortSamplingMode', @SetInpPortFrameData);
block.RegBlockMethod('SetInputPortDimensions', @SetInpPortDims);
block.RegBlockMethod('SetOutputPortDimensions', @SetOutPortDims);
block.RegBlockMethod('Outputs', @Outputs);
function SetInpPortFrameData(block, idx, fd)
block.InputPort(1).SamplingMode = fd;
block.OutputPort(1).SamplingMode = fd;
function SetInpPortDims(block, idx, fd)
block.InputPort(1).Dimensions = 1;
function SetOutPortDims(block, idx, fd)
block.OutputPort(1).Dimensions = [2 2];
function Outputs(block)
a=block.DialogPrm(1).Data;
block.OutputPort(1).Data = a;
|