How to extract or change the data in a Stateflow Chart using the 'get_param' command?
1 view (last 30 days)
Show older comments
MathWorks Support Team
on 29 Nov 2022
Edited: MathWorks Support Team
on 29 Nov 2022
When I check the data I created for use in the Chart in the Model Explorer, there is an initial value. I want to how to extract and change this initial value using the get_param command.
Accepted Answer
MathWorks Support Team
on 29 Nov 2022
Edited: MathWorks Support Team
on 29 Nov 2022
This is not possible with the get_param. You need to use the Stateflow API as shown in the example below.
bdclose all; clear all;
sfnew;
ch = find(sfroot,"-isa","Stateflow.Chart",Path="untitled/Chart");
data = Stateflow.Data(ch); % add a data object to the chart ch
data.Name = "x"; % specify name of the created data
data.Props.InitialValue = '1'; % specify the initial value of the data 'x'
data.Props.InitialValue % get the initial value of the data 'x'
The above-named 'x' data is an example of using the newly created data. The example code for finding an existing data name is as follows.
d = ch.find('-isa', 'Stateflow.Data','-and','Name','x'); % find data named 'x'
d.Props.InitialValue % extract the initial value of the data 'x'
d.Props.InitialValue = '2'; % change the initial value of the data 'x'
d.Props.InitialValue % get the initial value of the data 'x'
For more details on how to use the Stateflow API, please check the manual and reference links below.
https://www.mathworks.com/help/stateflow/api/quick-start-for-the-stateflow-api.html
https://www.mathworks.com/matlabcentral/answers/93271-how-can-i-view-edit-the-data-of-a-stateflow-chart-in-a-simulink-model-using-command-line-if-the-simu
0 Comments
More Answers (0)
See Also
Categories
Find more on Complex Logic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!