Embedded Matlab Fuction Access of Subsystem Mask Parameters

13 views (last 30 days)
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 Comment
Kyle Huggins
Kyle Huggins on 20 Dec 2018
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.

Sign in to comment.

Answers (2)

Kaustubha Govind
Kaustubha Govind on 7 Mar 2012
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 Comments
Phillip
Phillip on 7 Mar 2012
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 on 8 Mar 2012
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).

Sign in to comment.


Bala kumar
Bala kumar on 23 Jun 2015
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.

Products

Community Treasure Hunt

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

Start Hunting!