MATLAB Answers

Update section using Embedded matlab

1 view (last 30 days)
dab483 on 29 Nov 2011
MATLAB file S-Function contains an update and derivative section and an Output section.
If using embedded, i need to use integrator outside the block and input to the other block to get the output and get the same results as using derivative section Matlab S-function.
How about the update section? how to implement the update section of the MATLAB File S-function into an Embedded MATLAB block?

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 30 Nov 2011
I think you need to clear your thought. It sounds like that you want to use Embedded MATLAB Function to replace S-Function. To me, it sounds odd.
S-Function has a fixed template. It is suitable for describing a highly customized, or very complex system. Otherwise, basic Simulink blocks can be used to construct the system. Of course, S-Function has many other uses, but basically, it allows the user to put a customized system into Simulink environment following a pre-defined template.
The model derivative is usually used to describe a continuous system,e.g. non-linear or time-variant. You just need to describe the derivative so when you run simulation using different solver, the solver can be applied to calculate the integration based on the derivative. The model update, on the other hand, is typically for discrete system. You just need to describe how the state of the S-Function get updated at the specified time event. Many times, you don't need to have both in one S-Function unless you have a complex hybrid system.
The Embedded MATLAB Function can be stretched to implement the functionality of an S-Function. But, for a continuous system, the Embedded MATLAB function will probably need to implemented a fixed solver thus lose the flxibility. Or as you did, put all the integrators (continuous states) outside of the Embedded MATLAB Function. For discrete system, the Embedded MATLAB Function will probably need to declare many persistent variables to record the discrete states. So it is not the most straightforward way to implement a system with states, whether continuous or discrete.
If your system has states, use S-function. Otherwise, use Embedded MATLAB function. All assume that the system is complex and the basic Simulink blocks are not sufficient.
dab483 on 30 Nov 2011
Thank you so much. :)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!