MATLAB: Can I have PWork vector available in InitializeSampleTimes and SetWorkWidths function calls in the C MEX S function in Simulink 7.6 (R2010b)

simulink

I would like to have a PWork vector available in the 'InitializeSampleTimes' and 'mdlSetWorkWidths' functions for in my C MEX S function. This is for the purpose of checking the sizes of my input port width in each function call.

Best Answer

You can assign the PWork vector in either one of the functions InitializeSampleTimes or SetWorkWidths but not both. Chronologically, the InitalizeSampleTimes function is called prior to the other. There can be only be one PWork vector for each block in your model.
In the case when you know the size of the vector, you can choose to set the PWork vector in the InitializeSampleTimes function. However, you would have to use the PWork vector assignment in the SetWorkWidths function if the initial size of the vector is not known.