From the command window I would like to rename all states that are in a Stateflow chart. I'll use the following built-in model as an example. In the chart there are two states, Off and On, that are grouped by the Heater box.
I am receiving the error "Cannot change states inside a grouped state." when renaming the Off and On states because they are grouped by a box. If I simply double-click on the state name, I can easily rename via the usual Stateflow GUI, but I need to be able to do this in a script.
sys = 'sldemo_boiler';
rt = sfroot;
model = rt.find('-isa', 'Simulink.BlockDiagram', '-and', 'Name', sys);
charts = model.find('-isa', 'Stateflow.Chart');
c = charts(1);
states = c.find('-isa', 'Stateflow.State');
state_off = states(1);
state_off.Name = 'NewName';
How can I rename these states? I considered just ungrouping the box by unsetting its IsGrouped parameter, but state objects don't have a parameter that tells me what object they are grouped by, so I can't trace up the hierarchy.