How can I implement an MATLAB file S-Function into an Embedded MATLAB block?

1 view (last 30 days)
I have an M ATLAB file S-Function that contains a Derivatives section and an Output section. I want to generate code for my Simulink model but MATLAB file S-Function can not generate code.
I have verified that all the MATLAB functions I use are supported by the Embedded MATLAB block. I can not find a solution to implement the Derivatives section of the MATLAB File S-function into an Embedded MATLAB block.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Dec 2021
Edited: MathWorks Support Team on 13 Dec 2021
Ability to write algorithms (involving derivatives) and then generate code from it, is now available in Matlab System Block in Simulink R2013a and later. For example refer to:
For older releases (i.e., prior to R2013a):
The ability to implement derivatives is not available in Embedded MATLAB, Real-Time Workshop 7.2 (R2008b).
As a workaround, it is possible to use two Embedded MATLAB blocks and one integrator to implement this functionality. The first Embedded MATLAB block computes the derivatives of the states. An Integrator block is used to compute the states and a second Embedded MATLAB block is used to compute the Outputs.
The attached model demonstrates this implementation.

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products


Release

R2008a

Community Treasure Hunt

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

Start Hunting!