How to read the value of a 'Local' Data field in stateflow using Simulink test?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Renato SL
2019-9-4
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 个评论
Renato SL
2019-9-4
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.
更多回答(1 个)
Renato SL
2019-9-4
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Inputs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!