Can not save enumeration created by Stateflow

34 次查看(过去 30 天)
Andy
Andy 2024-11-11,16:38
回答: Ashok 2024-11-19,3:12
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?

回答(1 个)

Ashok
Ashok 2024-11-19,3:12
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!

类别

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