Simulink Matlabfunction does not support Global Optimization toolbox

조회 수: 3 (최근 30일)
Hi there,
I recently use Global Optimization toolbox in Simulink Matlabfunction to solve global optimization problem. But it always report a bug. Does Simulink Matlabfunction support Global Optimization toolbox ?
Best regards,
  댓글 수: 5
Walter Roberson
Walter Roberson 2025년 3월 20일
Turn Rapid Acceleration off for the model.
tianyuan wang
tianyuan wang 2025년 3월 20일
I have set “Rapid Acceleration” to “Normal”.
But the problem still exists.
Here I share my model for reference
Thank you very much for your help
Best regards,
Tianyuan

댓글을 달려면 로그인하십시오.

채택된 답변

Paul
Paul 2025년 3월 20일
The MatlabFunction block always generates code, even in Normal mode.
One option that may be workable is to implement your optimization function in an ordinary, Matlab, .m-function file with inputs that you'd expect to get from Simulink and outputs to send back to Simulink. Then declare that function with coder.extrinsic inside a Simulink MatlabFunction that serves as the wrapper to your function that does the actual work.
  댓글 수: 10
Paul
Paul 2025년 3월 21일
편집: Paul 2025년 3월 21일
Simulink generates code for the MatlabFunction block and that code is statically typed, which means the code generator has to be able to determine the class and size of each variable. Also, a Simulink model is static (by and large) and so Simulink can determine the class and size of all signals in the simulation when the model is compiled (I might be being a bit loose with terminlogy). For the MatlabFunction block, therefore, the size and class of the inputs to the function are known and then the code analysis tries to figure out the rest (sometimes also by back propagating information on the output side of the block). In this case, the code analysis isn't smart enough to figure out, at code generation time, if the if statement is going to be true or not, and therefore cannot know how to dimension bPosGlobal in the generated code. Matlab, of course, is much more flexible about this kind of stuff.
Having said all of that, I don't understand why it's a problem. It seems to me that you should know (or can force) the dimensions of bPosGlobal in Simulink, and therefore the dimension check shouldn't be needed in the MatlabFunction.
tianyuan wang
tianyuan wang 2025년 3월 21일

Thank you very much for your kindly reply. Now I understand why the error happens.

Best regards,

Tianyuan

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by