S-Function: How to set inherited sample time from C/C++
When writing S-Functions for Matlab/Simulink in C or C++, you can set the inherited sample time in mdlInitializeSampleTimes()
using
static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetOutputPortSampleTime(S, 0, INHERITED_SAMPLE_TIME);
}
This example only shows how to set the sample time for the first output port (index 0
). You can set it for input ports using ssSetInputPortSample()
static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetInputPortSampleTime(S, 0, INHERITED_SAMPLE_TIME);
}
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow