Simulink Matlabfunction does not support Global Optimization toolbox
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
tianyuan wang
am 20 Mär. 2025
Bearbeitet: Walter Roberson
am 22 Mär. 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 Kommentare
Akzeptierte Antwort
Paul
am 20 Mär. 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 Kommentare
Paul
am 21 Mär. 2025
Bearbeitet: Paul
am 21 Mär. 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!