MATLAB Answers

Is there a way to generate a C Source Mex file out of a Simulink model?

25 views (last 30 days)
Sören Behnsen
Sören Behnsen on 24 Aug 2016
Answered: Archit Dhanani on 29 Jul 2019
I am able to create a s-Function of my Simulink model with the help of the Simulink Coder.
But: I need to build a C Mex file of that Simulink model.
The example: My aim is to model a plant and a controller in Simulink. The controller is a model based controller and inhabits a discrete model of the plant, called model_p. Now this model_p should be a C Mex file for computation times sake. The controller is supposed to be a Matlab-Function or a s-Function with a sample time of let's say Ts=0.1s. So every timestep n*Ts the controller's output is a new control value for the plant. And every timestep the controller calls the model_p within its function to calculate several variations of the next control value and determine the best next control value by searching for the best suited output of the model_p. If interessted, look for particle swarm optimization.
Back to my problem: I do not know how to call the model_p other than as a function. Therefore I need this model_p to be C Mex file. Is there a way to generate a C Source Mex file out of a Simulink model?

Community Treasure Hunt

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

Start Hunting!

Translated by