How to compile a Matlab script using Matlab coder which calls a Simulink model

2 views (last 30 days)
Hi,
I created a Simulink model which simulates the energy consumption of a simplified car. The input of the model is a velocity profile and by using basic mechanic formulas is translated into the energy consumption. So input = velocity profile, output = energy profile.
The velocity profile is generated by a m-file (matlab script) based on the target destination to where the car has to drive to. This m-file calls the Simulink model after the velocity profile is generated. After running the Simulink model the script plots the velocity profile together with the energy consumption.
Now my question is: i want to make C-Code from the m-file but after some research on Matlab Central i discovered that its not possible to use the 'sim' command. I found a Matlab question similar to my problem, but the topic was taken offline.
I know i can compile the Simulink model to C (or an executable) using the Simulink coder, which i did. But i don't know the next step, calling the C-code (of the Simulink model) in the original m-script to compile all together with Matlab coder. I also don't understand how the Simulink input (velocity profile) and output (energy profile) is translated into a input and return value in the c-code and how to manipulate them after compilation.
Thanks in advance, Simon

Answers (2)

Arnab De
Arnab De on 23 Oct 2014
In order to call an external C function from your MATLAB code that you want to use for code generation, you need to use coder.cevel.

Andreas Goser
Andreas Goser on 9 Mar 2015
Please have a look at the bug report mentioned in the intitial request that was taken offline.

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!