MATLAB: Do I receive an error when I pass a vector to an Embedded MATLAB Function Block and manipulate it inside the block code in Simulink 6.0 (R14) and later versions

blockcolumnembeddedfunctionrowsimulinkvector

I have passed a vector into an Embedded MATLAB Function Block and then attempted to assign all or part of this vector to another vector using standard array indexing notation in the Embedded MATLAB code. However, when I try to run the simulation I receive a "size mismatch" error which may state the following:
Empty index expressions are not yet supported

Best Answer

This is the expected behavior of the Embedded MATLAB Function block. If a vector signal is created with the constant block, it has the option "Interpret vector signals as 1-D". When this is checked inside the model, the inputs to the Embedded Function block are treated as one-dimensional rather than two-dimensional. With this option checked, the inputs become column vectors inside the Embedded Function block rather than the row vectors that you created them as. Therefore, the indexing that you used in the Embedded Function block was transposed. The best way to fix this problem is to uncheck the 1-D option in the constant blocks.
Sometimes there is an error due to a mismatch in size between the result of the function and the variable which you were assigning to the result. The variables in an Embedded Function block are created as scalars unless you initialize them with zeros(m,n). If a vector is created with this option deselected, the orientation of the vector as it exists in Simulink (1 x N or N x 1) will be respected when it is passed into the Embedded MATLAB Function Block.
You can find more information on similar issue on the following MatlabCentral webpage:
<http://www.mathworks.fr/matlabcentral/newsreader/view_thread/165291>