Is there an example of dynamically sized input ports with different widths in a C-MEX S-function?

5 views (last 30 days)
I would like to know if there is an example of using dynamically sized input ports with different widths in a C-MEX S-function.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
Here is an example showing how to write a C-MEX S-function with dynamically sized input ports that accepts 1-D (vector) signals with different widths in Simulink 6.2 (R14SP2).
In Level 2 S-functions you need to use the two new methods: mdlSetInputPortWidth and mdlSetOutputPortWidth. This is described in the S-function section of the Using Simulink User's Guide.
If you open up the attached S-function source file, you will notice the following lines after mdlInitializeSizes:
#if defined(MATLAB_MEX_FILE)
# define MDL_SET_INPUT_PORT_WIDTH
static void mdlSetInputPortWidth(SimStruct *S, int_T port,
int_T inputPortWidth)
{
ssSetInputPortWidth(S,port,inputPortWidth);
}
# define MDL_SET_OUTPUT_PORT_WIDTH
static void mdlSetOutputPortWidth(SimStruct *S, int_T port,int_T outputPortWidth)
{
ssSetOutputPortWidth(S,port,outputPortWidth);
}
#endif
These methods are called with the candidate widths for dynamically sized ports. If the proposed widths are acceptable, the methods proceed to set the actual ports widths using ssSetInputPortWidth and ssSetOutputPortWidth.

More Answers (0)

Categories

Find more on Block and Blockset Authoring in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!