How to generate C code for both .m file and simulink?

2 views (last 30 days)
Mayank on 10 Mar 2014
Answered: Mike Hosea on 27 Mar 2014
I have designed a control logic in Simulink which takes inputs from a matlab scrpit file. I want to convert this logic into C so that it can be subsequently flashed into an ECU. What is the way ahead? Please note that I have the 2008b version.

Answers (1)

Mike Hosea
Mike Hosea on 27 Mar 2014
It's hard to remember what all was supported in 2008b, and I'm also not a Simulink expert. What does your MATLAB script really do? If it's just defining input data, then that can be handled as a purely Simulink thing, and you can generate code from your model using Real-Time Workshop. If it's implementing some kind of algorithm and calling sim(), then what you probably want to do is generate a library for your Simulink model and then write a driver for it in C that implements what your script is doing and calls into that library. If the algorithm in your script is really complicated, you might want to use emlc (I think it was still "emlc" back then--now it's called "codegen") to generate code for it, but you'll have to do some work to use coder.ceval to call into your library.

Community Treasure Hunt

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

Start Hunting!