Creating States with a MATLAB Function Block

조회 수: 7 (최근 30일)
MathWorks Support Team
MathWorks Support Team 2018년 1월 30일
답변: MathWorks Support Team 2018년 2월 27일
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?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2018년 1월 30일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by