How to read the value of a 'Local' Data field in stateflow using Simulink test?
2 views (last 30 days)
Show older comments
For whitebox testing (using Simulink Test) of a stateflow diagram I need to read some data field values which has its Scope type set to 'Local'. How can this be done?
0 Comments
Accepted Answer
Renato SL
on 4 Sep 2019
In the Model Explorer window (where you define data and its Scope type), when you click on a data, on your right hand side you can set certain parameters of the data.
Click on the Logging tab, and tick the Log signal data box.
This is a screenshot from my example.
After that, once you run the simulation, click on the Simulation Data Inspector button (beside the Simulation stop time box, top side of the Simulink window) and you can see the logged data there.
In the screenshot above, it's the one in the red circle.
I think it would turn yellowish once you run the simulation and you have a logged data.
I think this is how you can test the model without physically altering the blocks, which is what you are looking for.
2 Comments
Renato SL
on 4 Sep 2019
From the documentation of the data inspector (here), I believe it isn't meant to be used during runtime. For Matlab in general, I also think that observing data during runtime for the sake of seeing it change through time is not facilitated. (I found an interesting discussion here).
Other than observing the logsout through the command window, I think it's better to see it directly with the Simulation Data Inspector.
While opening the inspector, you could progress the simulation some steps at a time (by clicking the Step Forward button beside the Run button).
If this is what you meant by 'reading the logged value(s) at runtime', then this should be it.
More Answers (1)
Renato SL
on 4 Sep 2019
I think you should create a new data with Scope type set to 'Output'. This new data will just take the value of the concerned Local data so that it can be inspected from outside of the Chart.
%example
en:
x = 0; %the local data
du:
x = x + 1; %something is done to the local data
y = x; %the output data takes the value of the local data
I explored this possibility some time ago and I made this simple example (.slx file attached). I hope this helps.
See Also
Categories
Find more on Inputs 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!