How to retrieve a subblock name at initalization.

조회 수: 2 (최근 30일)
Thomas
Thomas 2013년 1월 4일
Dear community, I want to create a subblock which returns the name of the subblock as a String. (The subblock name shall be used as a key to retrieved a value from a database and I want to make the access of the database visible in simulink).
Currently I use a masked subblock with a 'Parameters' variable 'MyName'. The subblock contains a constant, which returns the value of a variable 'MyName'. The variable 'MyName' shall be initialized with the name of the subblock it belongs to.
A code like MyName = get_param(gcb,'Name'); does not work in the Initialization box for the dialog variable 'MyName'.
Since the subblock name is static I guess Simulink provides something like 'this.Name', which is available at initialization time. Is this kind of function available?
Can anyone help?

채택된 답변

TAB
TAB 2013년 1월 4일
Hope the parameter with same name as block name is present in the base workspace whose value will be assigned to mask variable MyName in the Mask Initialization.
In mask initialization pane, write,
MyName = evalin('base',get_param(gcb,'Name'));
  댓글 수: 5
Thomas
Thomas 2013년 1월 4일
Your hint gave me the solution. If I put in the Initialization pane for MyName
MyName=cast(char(evalin('base',get_param(gcb,'Name'))), 'uint8');
then I get the Subsystem name as an output. Thank you for your help.
Thomas
Thomas 2013년 1월 4일
The shortest solution is:
MyName=cast(char(get_param(gcb,'Name')), 'uint8');

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Doug Eastman
Doug Eastman 2013년 1월 4일
Another simpler option might be to just use a constant block with the value:
uint8('LookupKey')
You could then hide the block name and expand the block so that value text is visible.

카테고리

Help CenterFile Exchange에서 Automated Driving Toolbox에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by