Is it possible to use MATLAB Compiler to generate C code to be used with Real-Time Workshop?

5 views (last 30 days)
I have a Simulink model that calls a MATLAB file with the MATLAB Fcn block. I am using Real-Time Workshop (RTW) and am aware that I cannot generate C code from this block. I would like to use the Compiler to generate a C MEX-file, include this file in my model, and then use RTW to generate code.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Nov 2016
Beginning with Simulink 6 (R14), the Embedded MATLAB Function block provides an embeddable subset of the MATLAB language that can be used to generate embeddable C code using Real-Time Workshop. Read the following documentation on 'Integrating External MATLAB Code' for more information:
To migrate from the MATLAB Fcn block, you must currently copy and paste your MATLAB code from the existing MATLAB Fcn block's MATLAB file into an Embedded MATLAB Function block. If you are using portions of the MATLAB language that are not supported by Real-Time Workshop, the block will still simulate but will display the unsupported lines of code and will generate code using Real-Time Workshop only after you replace the unsupported code with supported language elements. For more information on the Embedded MATLAB Function block, refer to the documentation:
Using the Embedded MATLAB Function Block
NOTE: It is true that prior to MATLAB Compiler 4.0 (R14), the MATLAB Compiler had a -S flag that would compile a MATLAB file S-function into a .dll file via C code generation. This code was not supported at all on non-MATLAB host computers. It was also not suitable for use in embedded systems and did not run outside the MATLAB environment. MathWorks has changed the MATLAB Compiler and Real-Time Workhop in Release 14 to be clearer as to what the products are intended for:
- The MATLAB Compiler is for desktop application deployment
- Real-Time Workshop is for creating portable standalone C code from Simulink models (Stateflow is supported via Stateflow Coder).

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!