MATLAB: How to get the “product” block to automatically transpose matrices in Simulink 7.3 (R2009a)

automatic;simulinktranspose

I am multiplying two matrices using the "product" block in matrix multiplication mode. If the inner dimensions of the matrices do not match, I would like for Simulink to automatically transpose the matrices so that they can multiply.

Best Answer

There is no direct way in the "product" block to detect the need for matrix transpositions in Simulink 7.3 (R2009a). This is done intentionally, as often a signal size mismatch indicates that something is wrong with the model.
As a workaround, this can be done using the Embedded MATLAB Function block. Attached is an example that will transpose the matrices as necessary to allow multiplication.
Inside the 'Transposed Matrix Multiplication' block, open the 'Embedded MATLAB Function' block. The code checks the dimensions of the input matrices, and if they do not allow multiplication untransposed, it tests to see if it would be possible by transposing the first, second, or both matrices. If none of these scenarios works, it outputs the original matrices, and Simulink will display the error that you would normally see when the matrices are improperly sized.