MATLAB: Do I receive an “Error in port widths or dimensions” error when I set default input dimensions in Simulink when the input ports are initialized dynamically

2dynamiclevelports-functionsimulink

I have created a Level-2 MATLAB file S-function. I have two inputs. One of the inputs is a vector and the other input is a matrix. I use the following code to initialize the dimensions of my inputs:
block.SetPreCompInpPortInfoToDynamic;
By doing this, I receive the following error: ERROR: Error in port widths or dimensions.

Best Answer

In order to use several ports which inherit their dimensions from the input ports, you can use the SetInpPortDims method as follows
block.RegBlockMethod('SetInputPortDimensions', @SetInpPortDims);
function SetInpPortDims(Block, port, dims)
Block.InputPort(port).Dimensions = dims;
 The attached example illustrates this.