Can not save enumeration created by Stateflow

조회 수: 25 (최근 30일)
Andy
Andy 2024년 11월 11일
댓글: Laurent Royer 2024년 11월 23일 17:05
StateFlow can create an enumeration when outputing a monitor port, but can also use a manually created enumeration that match the state names. What I would really like to do is save the StateFlow-created enumeration, and then for future model runs select "Define enumeration type manually". This would a) avoid having to type the enumeration from scratch, and then b) eliminate all the red block highlighting when the model opens (before it builds). Is there a way to do this?
  댓글 수: 2
Andy
Andy 2024년 11월 23일 16:11
I worked with the suggestions from other users, and while I learned a lot in the process what I had to do was start with this enum definition template, and then reassign "(0)" to match what the initial state arrow was actually pointing at. I'll now have to manually maintain that enum as the STD grows or changes.
Laurent Royer
Laurent Royer 2024년 11월 23일 17:05
I'm surprised you want the initial child state to have the zero value. Once using enumeration type, the actual numerical values should not matter.
I understand your solution, but this again gives me an idea to improve my tool: When importing the state monitoring data, I'll automatically update the existing class file, just as you intend to do manually :)

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

채택된 답변

Andy
Andy 2024년 11월 23일 16:14
see the self-comment.

추가 답변 (2개)

Ashok
Ashok 2024년 11월 19일
Hey @Andy,
Stateflow does not have a direct feature to output the enumeration definition. here's a workaround that might be useful. In a Stateflow chart where the Enum type 'ModeLogicModeType' is created, the output of the 'Child activity' monitor can be logged using an 'Outport' as shown below.
To gather the enumeration class name, members, and their corresponding numeric values, the following lines of code can be used:
[enumMembers, memberNames] = enumeration(out.yout{1}.Values.Data);
memberValues = double(enumMembers);
enumName = class(out.yout{1}.Values.Data);
This data can then be used to define an enumeration type using the ‘Simulink.defineIntEnumType’ function. More information on this function can be found here:
To list all custom enumerations, present in the current MATLAB session, refer to this MATLAB Answer:
I believe this will assist you!
  댓글 수: 1
Andy
Andy 2024년 11월 23일 16:12
This for the suggestions, and I learned a lot trying them, but what I had to end up using in my self-answer. Still, thanks a 1e+6.

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


Laurent Royer
Laurent Royer 2024년 11월 22일 23:24
Thanks for your question about enumerations for states monitoring! It gave me the idea to add a new feature to this Enumeration Manager available in File Exchange.
So this manager now allows to easily generate the enumeration class files corresponding to the enumeration types generated by Stateflow. Hope this helps.
Also note that if by any chance, you're enabling the monitoring feature for 2 distinct states having the same name (possibly located in 2 charts of the same model), you'll have to manually change the name of one of the 2 generated enumeration classes to avoid a conflict. Actually it would be possible to use one single enumeration class for these 2 states, defined as a union of members from both classes. This is something I could add to my manager if needed.
  댓글 수: 1
Andy
Andy 2024년 11월 23일 16:14
I downloaded the Enum Manager; looks interesting. Still what I had to end up doing is in my self-answer above. Still, thanks a 1e+6.

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

카테고리

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

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by