Saturday, 28 September 2013

Matlab Function will not output correctly in Simulink

Matlab Function will not output correctly in Simulink

I have a relatively simple function that I'm importing into Simulink:
function q2dot = cq2dot(m,l,u,q,qdot)
M = [3+m(3), -cos(q(2)), -m(3)*l(2)*cos(q(3)); -cos(q(2)), 1, 0;
-m(3)*l(2)*cos(q(3)), 0, m(3)*l(2)^2;]; K = [0 0 0; 0 -cos(q(2))*q(2) 0; 0
0 -m(3)*l(2)*cos(q(3))*q(3);]; q2dot = M\K;
The function works, and outputs a 3X3 matrix when I execute it in Matlab.
However, when I put it into Simulink using the "Matlab-interpreted
Function" block, the output is automatically collapsed from a 3X3 Matrix
into a 1X9 Array. I have unchecked the box that says "Collapse 2-D output
into 1-D" in the function block, which fixed nothing. Because of this, any
nonzero initial values I add give me errors. Anybody have any tips on how
to fix this?

No comments:

Post a Comment