Embedded Matlab Fuction Access of Subsystem Mask Parameters
8 views (last 30 days)
Show older comments
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
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.
Answers (2)
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
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).
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.
0 Comments
See Also
Categories
Find more on Subsystems in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!