Why does the initialization function in a Simulink subsystem block use an integer rather than the corresponding text string?
이전 댓글 표시
There is an example Simulink file attached. I created a parameter on the "Parameter & Dialog" tab called Parameter1. Parameter1 is a popup and has 3 possible values Option 1, Option 2, and Option 3 as shown below.

 
If I query Parameter1 from the command line get_param(gcb, 'Parameter1'), I find the value to be one of the three options listed (see picture). However, if I use Parameter1 as a variable in the Initialization tab, it acts like integer (see 2nd picture below). I understand that Simulink is really using Enumeration. Is there a way I can use/invoke this Enumeration in the initialization of my subsystem?

 

채택된 답변
추가 답변 (1개)
Ankit Bhatnagar
2017년 2월 9일
0 개 추천
I understand that you are trying to utilize the mask parameters to initialize your subsystem.
1. As you used the get_param for 'Parameter1', you can also use set_param to assign it a value.
2. You can enter any valid MATLAB expression, consisting of MATLAB functions and scripts, operators, and variables defined in the mask workspace. However, Initialization commands run in the mask workspace, not the base workspace.
3. Additionally, there is a check box on the same window:
'Allow library block to modify its contents'
This check box is enabled only if the masked subsystem resides in a library. Checking this option allows the block's initialization code to modify the contents of the masked subsystem by adding or deleting blocks and setting the parameters of those blocks. Otherwise, an error is generated when a masked library block tries to modify its contents in any way.
Refer the following documentation link to read more about the Initialization tab and check out a simple tutorial as well.
- http://www.mathworks.com/help/simulink/gui/mask-editor-overview.html#bu086do
- https://www.mathworks.com/videos/creating-a-mask-parameters-and-dialog-pane-120557.html
You can also use the 'Initfcn' callback of a particular block itself for initialization purposes.
댓글 수: 1
Jason Nicholson
2018년 3월 21일
편집: Jason Nicholson
2018년 3월 21일
카테고리
도움말 센터 및 File Exchange에서 Subsystems에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
