What is the best way to do some calculation within a state in stateflow?

조회 수: 9 (최근 30일)
Dear all, I'm bit confused of selecting a method to do some calculating program in a 'State' of the Stateflow. I do have to calculate some values checking some external measurements within a 'State'. I used to write some codes of calculation in the state block like Matlab script, but I then moved this code to Matlab Function block, since the state machine just better to show the state changes visually. Still, I am looking for the best way of doing such thing in sateflow while minimizing the execution time. Can anyone suggest me a better way to do such things (writing matlab codes in stateflow states)?

채택된 답변

Zhao Wang
Zhao Wang 2016년 9월 28일
I understand that you want to find a better way to write MATLAB code in Stateflow states. I am not sure in what sense you mean better. It might be shorter execution time, easier maintenance, or something else.
I assume you want to make the Stateflow chart easier to change than directly editing MATLAB code in a 'State'. In order to achieve this, you can include MATLAB functions in a Stateflow chart. Refer to the following link for more details about using MATLAB functions in a Stateflow chart:
If you have any specific question, you can contact MathWorks Technical Support for further assistance.
  댓글 수: 1
Tharindu Weerakoon
Tharindu Weerakoon 2016년 9월 30일
Thanks Zhao. Right now I am using the same technique.
BTW, I want to access the variables used in the MATLAB function in Stateflow chart, which should be defined as a global variable. Also the input parameters should be defined globally and they will be updated every time. In the state chart, I will execute the matlab function and it will calculate many parameters/variables and I will be able to get them without defining input and output when I call the function ([output] = Function_Name(inputs)) as explained in this example.
I have post this question in detail, and can you suggest a way to do this?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Complex Logic에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by