Accessing the states of a stateflow chart located inside a reference model using the model operating point

5 visualizaciones (últimos 30 días)
Hello,
I have a large simulation model with many reference models included in it in multiple levels. Within many of these reference models, there are stateflow charts, and I would like to access the states of these charts and modify them. To that end, I have saved the operating point of the model. However, neither do the states of interest appear under loggedStates, nor I can access them using the 'get' command. When I use 'get,' I get this error message:
>> get(xFinal,'MySimulinkModel/ReferenceModel1 (ReferenceModel1)/ReferenceModel2 (ReferenceModel2)/StateflowChart')
The operating point for block 'MySimulinkModel/ReferenceModel1 (ReferenceModel1)/ReferenceModel2 (ReferenceModel2)/StateflowChart' is not accessible.
Try one or more of the following:
1. Ensure the block path is valid.
2. Set operating point compliance setting of the block to 'Custom'.
3. Set operating point visibility setting of the block to 'on'.
4. If the block is inside of a referenced model, configure the model reference and the top model to be in normal mode.
5. If this is a built-in Simulink block, access logged states through 'loggedStates' property.
Item 4 above does not apply in my case, and I cannot find any information on how to access properties mentioned in Items 2 and 3.
I should note that, in the above, I have changed the block names, but I am certain the block path is correct.
I should add that I have looked at 'sf_car' example and tried it, and it works.
Any help will be very much appreciated.
Regards,
Kourosh Parsa

Respuestas (1)

Subhajyoti
Subhajyoti el 27 de Jun. de 2025
To access and modify Stateflow chart states in a Simulink model with referenced models:
1. Verify Path: Ensure the block path 'MySimulinkModel/ReferenceModel1/ReferenceModel2/StateflowChart' is correct using 'find_system('MySimulinkModel', 'BlockType', 'Stateflow')'.
2. Set Compliance and Visibility:
Open the Stateflow chart properties, set Operating Point Compliance to Custom, and Visibility to On. Or use the Stateflow API:
chartObj = sfroot.find('-isa', 'Stateflow.Chart', '-path', 'MySimulinkModel/ReferenceModel1/ReferenceModel2/StateflowChart');
chartObj.SaveOperatingPoint = true;
chartObj.Visible = true;
3. Save Operating Point:
xFinal = sim('MySimulinkModel', 'SaveOperatingPoint', 'on', 'SaveState', 'on');
4. Access States:
Check "xFinal.loggedStates" or use:
states = chartObj.find('-isa', 'Stateflow.State');
for i = 1:length(states)
disp(['State: ', states(i).Name, ', Active: ', num2str(states(i).isActive)]);
end
5. Modify States:
stateObj = chartObj.find('-isa', 'Stateflow.State', 'Name', 'YourStateName');
stateObj.isActive = true; % Modify as needed
xFinal = xFinal.setState(chartObj.Path, stateObj);
save('modified_op.mat', 'xFinal');
6. Load Modified States:
load('modified_op.mat', 'xFinal');
sim('MySimulinkModel', 'LoadInitialState', 'on', 'InitialState', 'xFinal');

Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by