Simulink Matlabfunction does not support Global Optimization toolbox

5 visualizzazioni (ultimi 30 giorni)
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 Commenti
tianyuan wang
tianyuan wang il 20 Mar 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

Accedi per commentare.

Risposta accettata

Paul
Paul il 20 Mar 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 Commenti
Paul
Paul il 21 Mar 2025
Modificato: Paul il 21 Mar 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 il 21 Mar 2025

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

Best regards,

Tianyuan

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by