Creating States with a MATLAB Function Block

4 Ansichten (letzte 30 Tage)
I want to include a Matlab algorithm in my model that has information which needs to persist over multiple time steps. Can I do this with a MATLAB Function block?

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 30 Jan. 2018
It is possible to model state behavior using a MATLAB Function block, by declaring the state variable as 'persistent'. However, this is not the recommended workflow if you need information to persist through multiple time steps, since these blocks can only "fake" a state using a persistent variable. This is simple to implement, but has limitations since persistent variables cannot be logged, stored, or retrieved in Simulink.
There are several other options for implementing a MATLAB algorithm in Simulink. The following documentation page is a wonderful resource for comparing the different options for implementing a MATLAB algorithm in a Simulink model:
It is recommended to review this page before making a final choice about which block to use to implement your algorithm, since it discusses many considerations to make when choosing between the options (e.g. code generation, performance). The section on "Model State Behavior" discusses which options can work with states.
Finally, one option that is not mentioned on the above page is to use Stateflow.

Weitere Antworten (0)

Kategorien

Mehr zu Simulink Functions finden Sie in Help Center und File Exchange

Produkte


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by