ssSetOutputPortDimensionInfo() example for a 2D matrix

Here’s how you can specify a 2D matrix output port in a Matlab/Simulink S-Function using ssSetOutputPortDimensionInfo(). In this example, we’ll specify a 7x7 matrix output port (49 elements in total).

#include "simstruc.h"

static int _outputSubDims[2] = {7, 7};
static DimsInfo_T outputDimsInfo = {
        7*7,
        2,
        _outputSubDims,
        nullptr
};


// Function: mdlInitializeSizes ==============================================
static void mdlInitializeSizes(SimStruct *S) {
  // ...  
  if (!ssSetNumOutputPorts(S, 1)) return;
  ssSetOutputPortWidth(S, 0, 49); // 7x7 elements

  ssSetOutputPortDimensionInfo(S, 0, &outputDimsInfo);
}