필터 지우기
필터 지우기

Embedded Matlab Fuction Access of Subsystem Mask Parameters

조회 수: 14 (최근 30일)
Phillip
Phillip 2012년 3월 7일
댓글: Kyle Huggins 2018년 12월 20일
Hi all,
Is it possible to access a subsystem's mask parameters from an embedded matlab function within that subsystem? I tried referencing the parameter name directly and I also tried the get_param function, neither of which worked. get_param(gcb,'myParameter') generated the following error: "The function 'gcb' is not supported by Embedded MATLAB for code generation. See the documentation for eml.extrinsic to learn how you can use this function in simulation." I looked at eml.extrinsic and did not immediately see how this would help me access parameters. Any help will be greatly appreciated.
Thanks,
Phillip
  댓글 수: 1
Kyle Huggins
Kyle Huggins 2018년 12월 20일
I know this is 6 years old, but I wanted to comment for future users. In order to access a masked parameter inside a matlab function block, you have to add your variable as an input into the matlab function.
Prerequisites. A mask set up correctly for a referenced model. See the reference documentation for how to do it.
1) Open the model explorer
2) click on and expand your referenced model
3) click on the matlab function inside your referenced model
4) on the taskbar, add a new data entry
5) set the name to your model workspace variable's name (same one that's masked as a parameter)
6) change the scope to "Parameter" (this is the important bit)
You're done! The variable should appear as a function argument in your matlab function, and it should have the masked value specified in the calling model. As long as all the names match up, it should work.

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

답변 (2개)

Kaustubha Govind
Kaustubha Govind 2012년 3월 7일
Embedded MATLAB Function Block parameters need to have the same name as the variable that holds its value, so you need to define your mask parameter variable name so that it matches that of the Embedded MATLAB block. If that's not possible, in the Mask Initialization pane, simply create a variable whose name matches that of the Embedded MATLAB parameter, and assign the value of the mask parameter to it.
I'd advise against using gcb because it returns whichever block is currently selected on the model, which doesn't have to be the masked subsystem. The error that you see asking you to use eml.extrinsic is because the Embedded MATLAB block only allows use of functions supported for code-generation, and the get_param function is not one of them.
  댓글 수: 2
Phillip
Phillip 2012년 3월 7일
I do not understand "define your mask parameter variable name so that it matches that of the Embedded MATLAB block". The mask parameters are identical to where I referenced them inside of the function. I reworked my function so that it's inputs include the subsystem mask parameters that I need. These inputs are now connected to constants that are oaded from the subsystem mask parameters.
Kaustubha Govind
Kaustubha Govind 2012년 3월 8일
If you have already defined your mask variables with the same name as the EML block parameters, you shouldn't have to use get_param(gcb,'myParameter') - just use the parameter name 'myParameter'. You may need to configure the parameters appropriate in the block's Ports and Data Manager (Tools>Edit Data/Ports on the EML Editor window).

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


Bala kumar
Bala kumar 2015년 6월 23일
Hi Phillip,
try the above link that will help you to get idea how to access the mask system parameter by a matlab function block.

카테고리

Help CenterFile Exchange에서 Subsystems에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by