Main Content


Set the default dimensions of the signals accepted or emitted by a C MEX S-function's ports




C, C++


void mdlSetDefaultPortDimensionInfo(SimStruct *S)



SimStruct representing an S-Function block.


The Simulink® engine calls this method during signal dimension propagation when a model does not supply enough information to determine the dimensionality of signals that can enter or leave the block represented by S. This method should set the dimensions of any input and output ports that are dynamically sized to default values. This method is only valid for simulation, and must be enclosed in a #if defined(MATLAB_MEX_FILE) statement.

If the S-function does not implement this method, the engine tries to find a set of dimensions that will satisfy the dimension propagation rules implemented using mdlSetInputPortDimensionInfo and mdlSetOutputPortDimensionInfo. This process might not be able to produce a valid set of dimensions for S-functions with special dimension requirements.

The engine invokes an error if the mdlSetDefaultPortDimensionInfo method attempts to modify the dimensions of a port when the dimensions were previously specified by mdlSetInputPortDimensionInfo or mdlSetOutputPortDimensionInfo. If an S-function has multiple input or output ports, mdlSetDefaultPortDimensionInfo should check if the dimensions of the port are still dynamic before attempting to set the dimensions. For example, the mdlSetDefaultPortDimensionInfo uses the following lines to check if the dimensions of the first output port are still unknown.

     if (ssGetOutputPortWidth(S, 0) == DYNAMICALLY_SIZED) {
        ssSetOutputPortMatrixDimensions(S, 0, 1, 1 );


See sfun_matadd.c for an example of how to use this function.

Version History

Introduced before R2006a