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.
When changing Constant to Constant2, the input sequence changes and therefore, my c-mex function is not correct.
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.
Asked
Active
Viewed 219 times
2

Bhargav Rao
- 50,140
- 28
- 121
- 140

steffenmauch
- 353
- 5
- 16
-
It seems that you have passed wrong paras to c-mex interfaces. In the second case where we could clearly see that the matrix is right but ordered into different orders. I suggest you to examine carefully the interfaces, especially specifying the order of elements in the matrix. – Jake0x32 Dec 27 '14 at 17:28
-
This is not the intended behaviour of a s-function, I assume an implementation error in your code. Please add the code you are using to the question. – Daniel Dec 27 '14 at 17:39
-
well, the point is: matA is dim 8x4 and matB 4x2. I used printf to see weather port[0] is 4x2 in both cases and it isn't. So why is the ordering inside the c-mex file changing depending on the name of the constant connected? The two pictures are just for visualization that the naming schema is somehow important. I haven't found any information about this till now ... – steffenmauch Dec 27 '14 at 17:41
1 Answers
0
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

Bhargav Rao
- 50,140
- 28
- 121
- 140

steffenmauch
- 353
- 5
- 16