![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/177651/image.png)
How initialise Output before a stateflow call
조회 수: 23 (최근 30일)
이전 댓글 표시
Good morning everyone,
I experience some trouble with working with Stateflow and outputs initialisation.
I have a stateflow with two outputs bool_Signal_1_Available and bool_Signal_2_Available. The first thing I do when the chart is called is to initialise these signals to the value true.
But before I call this statechart (I have a enable trigger on it), both values of this two outputs are set to "false" (initial value for boolean signal).
I have another chart in a different bloc that reads the outputs on the first one and detects an error when signals bool_Signal_1_Available or bool_Signal_2_Available are equals to false. Due to the bad initialisation, he detect the error before I will call my chart for the first time.
I would like to init these to "true" and not the default value of "false".
Do you have any ideas to fixe this ?
Thanks for helping me ! Have a good day
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/165750/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/165752/image.png)
댓글 수: 0
답변 (1개)
Navdeep Singh
2017년 8월 2일
You can initialize the Stateflow chart variable using Property Inspector. Chart's data properties can be set to get the desired model behavior. One of them is 'Initial Value' that can be set to a default value. This may help your case.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/177651/image.png)
댓글 수: 1
Paul Rancuret
2023년 4월 27일
@Navdeep Singh sorry to bring up a really old post, but I do have a further question about this. In my case, the data type I'm using for an Output item is a bus object. I'm using Matlab R2020b for right now, and I am using a 'Mealy' chart with the matlab action language.
For some reason, the 'Initial value' dialog box is greyed out and says "Not Needed". However, I really do want to specify the initial value. Many fields of the output struct get updated for various reasons at runtime. However, there are some fields which may not get written on a given update step. I would like these to remain at their previous value (using the initial value if they haven't been set at all yet). The default values I would like to use come from a model workspace parameter argument with the same bus object data type.
For now, I have worked around this by adding a statement in the chart which sets the entire output bus value equal to the default output parameter value on the first pass of the chart. I would really have preferred this copy operation to occur in the generated <modelName>_Initialize() function instead of on the first chart pass at run-time, because I really don't want the first pass to have this extra operation time compared to all subsequent passes.
Do you know why the 'Initial value' dialog box is greyed out and says "Not needed" in my case? I can't figure out how to enable it. I've also tried using a Simulink.Signal object for the output data item, but it still won't make use of that initial value when the 'auto' storage class is used for the Simulink.Signal object. It won't let me use any other storage class besides 'auto' if that signal object is in the model workspace (which it needs to be so that the default initial value is in the same context).
Please let me know if you have any further advice on what to do in this situation!
Thanks!
참고 항목
카테고리
Help Center 및 File Exchange에서 Simulink Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!