Simulink Matlabfunction does not support Global Optimization toolbox
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
tianyuan wang
il 20 Mar 2025
Modificato: Walter Roberson
il 22 Mar 2025
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
Risposta accettata
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
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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!