MATLAB: How to link Simulink requirements to specific states within a Stateflow chart

Simulink Requirements

How can I link Simulink requirements to specific states within a Stateflow chart?

Best Answer

You can have a Stateflow.Object or a numeric ID for the Stateflow object as one of the arguments to the "rmi" function. You can refer to the following link for more information:
To get hold of the Stateflow.State objects, you can run the following commands in the MATLAB command window:
>> modelObj = get_param(bdroot, 'Object')
>> sfStates = find(modelObj, '-isa', 'Stateflow.State')
Now you have all the states, and you can link any one by using sfStates(n) as the second argument to the "rmi" function. For example:
>> rmi('cat', sfStates(1), reqSimLinks(iList))
Alternatively, you can use the numeric ID of the specific state. You can check the state ID by executing sfStates(n) in the MATLAB command window and checking the information it displays. For example:
>> sfStates(1)
If the ID is 24, for example, you can use it as follows:
>> rmi('cat', 24, reqSimLinks(iList))
You could also find a specific state by providing a 'name argument'. For example:
>> warmupState = find(modelObj, '-isa', 'Stateflow.State', 'name', 'warmup')
>> rmi('cat', warmupState, reqSimLinks(iList))