MATLAB Answers

0

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

Asked by Sören Behnsen on 24 Aug 2016
Latest activity Answered by 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?

  0 Comments

Sign in to comment.

1 Answer

Answer by Archit Dhanani on 29 Jul 2019

writing a tlc file for the SFunction will assist in code generation. You can read the discussion on the page below:

  0 Comments

Sign in to comment.