Update section using Embedded matlab
2 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
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.
4 Comments
Fangjun Jiang
on 30 Nov 2011
Quote from the documentation. "Note The information provided in this section is intended only for use in maintaining existing M-file S-functions based on Level-1 API. You should use the more capable Level-2 API to develop new M-file S-functions (see Writing Level-2 M-File S-Functions).
Level-1 M-file S-functions do not support multidimensional signals."
So, go straight to Level-2.
More Answers (0)
See Also
Categories
Find more on Block and Blockset Authoring 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!