- Open the Simulink model and open the "Configuration Parameters" using ctrl + E.
- Under the Code Generation Tab, select the "System target file" as "ert_shrlib.tlc" from the browse option.
- Build the model and ".dll" files will be generated for the model.
Use Simulink DLL to Simulate a system in fmincon
1 view (last 30 days)
Show older comments
I need to run a Simulink model that runs an optimization with fmincon each time step. This model must be suitable for code generation. I know that fmincon is compatible for code generation but calling another simulink model from a simulink model is not.
The workflow should be as follows: ModelA has a block that returns optimal settings each time step. To do so, ModelA feeds its current settings to fmincon, which then returns the optimal settings using ModelB as objective function.
I tried using ode45 and represent ModelB as an ODE system and it worked, but it becomes impractical for larger systems with complex models.
While looking online I saw that there is a way to export simulink models as shared libraries. I'm new to code generation and have no idea on how to run a shared library as a simulation so I can get the same results as running ModelB directly from simulink.
So the question is, how can I export a Simulink model as DLL and make it run as a simulation?
Also is there is anyone know a better way to do this sort of optimization, please let me know. It should be compatible for code generation.
P.D. This also need to work in 2021b
Thanks in advance,
Jose
0 Comments
Answers (1)
Ashutosh
on 24 Aug 2023
The steps to generate a shared library version of the model code are:
There are several ways to use the ".dll" files, refer to the following link for more information: https://in.mathworks.com/matlabcentral/fileexchange/44197-calling-shared-libraries-from-simulink
The ".dll" files can also be loaded in form of C S-Functions, to know more about S-Functions refer to the link: https://in.mathworks.com/help/releases/R2021b/simulink/sfg/example-of-a-basic-c-mex-s-function.html
The links mentioned below would help in loading and calling of functions of ".dll" files in MATLAB:
0 Comments
See Also
Categories
Find more on Simulink Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!