Search code examples
matlabsimulinkmexs-function

How to determine input sequence in c-mex s-function?


I am implementing a c-mex sfunction in simulink for accelerating the multiplication of two matrices. So far it is working, but I found out that the input ordering/sequence is depended of the naming schema of the connected e.g. constants. I attached two pictures for explanation: First, I named the inputs Constant and Constant1. Then, the input sequence is as expected. enter image description here When changing Constant to Constant2, the input sequence changes and therefore, my c-mex function is not correct. enter image description here Now, my question is how could I change this behaviour? If it is not possible how can I implement a workaround, because the ordering for matrix multiplication is in general very important.


Solution

  • I found a solution. When you also print the port in mdlSetInputPortDimensionInfo, you see that depending of the naming schema, the sequence of the calling is different. My workaround is to set the output port dimension in mdlSetDefaultPortDimensionInfo based on the InputDimension I read back with ssGetInputPortDimensionSize.

    The complete code can be found at Github: https://github.com/steffenmauch/Simulink-Eigen3