MATLAB: Do I receive an error message when I use the ssSetInputPortWidth macro in the C MEX S-function that takes frame-based input

frames-functionsimulinksssetinputportframedatasssetinputportmatrixdimensionssssetinputportwidthsssetoutputportmatrixdimensionssssetoutputportwidth

Why do I receive an error message when I use the ssSetInputPortWidth macro in my C MEX S-function that takes frame-based inputs?
I want to design a C MEX S-function that has frame-based inputs and outputs. Besides, both input and output sizes need to be dynamically sized. My mdlInitializeSizes callback reads as follows:
static void mdlInitializeSizes(SimStruct *S)
{
// Input port
if (!ssSetNumInputPorts(S, NUM_IMPORT)) return;
ssSetInputPortFrameData(S, INPORT, FRAME_INHERITED);
ssSetInputPortComplexSignal(S, INPORT, COMPLEX_NO);
ssSetInputPortWidth(S, INPORT, DYNAMICALLY_SIZED);
ssSetInputPortDirectFeedThrough(S, INPORT, TRUE);
……
// Outputs
if (!ssSetNumOutputPorts(S, NUM_OUTPORT)) return;
ssSetOutputPortFrameData(S, OUTPORT, FRAME_INHERITED);
ssSetOutputPortComplexSignal(S, OUTPORT, COMPLEX_NO);
ssSetOutputPortWidth(S, OUTPORT, DYNAMICALLY_SIZED);
……
}
After I compiled my s-function and ran my model, I received the following error message:
Cannot set port 0 of block 'untitled/S-Function' to have one dimension when this port is set to be frame-based. For a frame-based port, the number of dimensions should be greater than 1

Best Answer

After you set the input of an s-function to frame-based using the macro:
ssSetInputPortFrameData(S, INPORT, FRAME_INHERITED);
You will not be able to make the input dynamically sized using the macro:
ssSetInputPortWidth(S, INPORT, DYNAMICALLY_SIZED);
because the ssSetInputPortWidth macro is not supposed to be used with a frame-based input.
Please use the following macro instead:
ssSetInputPortMatrixDimensions(S, INPORT, DYNAMICALLY_SIZED, DYNAMICALLY_SIZED);
Likewise, you should use the following macro to make the frame-based output dynamically sized:
ssSetOutputPortMatrixDimensions(S, INPORT, DYNAMICALLY_SIZED, DYNAMICALLY_SIZED);