Simulink Matlabfunction does not support Global Optimization toolbox

2 visualizaciones (últimos 30 días)
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 comentarios
Walter Roberson
Walter Roberson el 20 de Mzo. de 2025
Turn Rapid Acceleration off for the model.
tianyuan wang
tianyuan wang el 20 de Mzo. de 2025
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

Iniciar sesión para comentar.

Respuesta aceptada

Paul
Paul el 20 de Mzo. de 2025
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 comentarios
Paul
Paul el 21 de Mzo. de 2025
Editada: Paul el 21 de Mzo. de 2025
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 el 21 de Mzo. de 2025

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

Best regards,

Tianyuan

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by