Is there anybody to help me fix the error and convert mxArray to double?

14 次查看(过去 30 天)
I am trying to implement the m-file into Matlab Function in Simulink. It needs to run some code conversion. Since "care()" function is not in the main library of this code converter, I have added coder.extrinsic('care'). Now when I run the Simulink it shows me the error as in the attached figure.
coder.extrinsic('care')
[~,~,G0] = care(hA, hB2, eye(4), eye(1), zeros(4,1), E);
KK=G0;
bA=hA-hB2*KK;
Now in my case bA(4x4 matrix), hB2(4x1 double), KK(1x4 mxArray). In fact after multiplication bA*hB2 should return 4x4 matrix. The problem is that KK should be double in order to work. How can I fix this issue of converting mxArray to double?
The code runs ok on m-file, but when I try to implement it on Simulink, it doesn't. I plan later to convert it to C++ code.

采纳的回答

James Tursa
James Tursa 2017-8-29
What happens if you add this prior to the "care" call:
G0 = zeros(1,4);
  2 个评论
Drill Be
Drill Be 2017-8-31
Thank you, it works. But now I faced another similar issue with mxArray when I want to multiply two state space systems. For instance G12*KK, it shows the same error mxArray. Both are State-space model with 3 outputs, 1 inputs, and 4 states.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by