Can I access the Unit of a Simulink.Parameter in a Mask?

6 ビュー (過去 30 日間)
Julius Rauh
Julius Rauh 2020 年 9 月 9 日
編集済み: Julius Rauh 2020 年 9 月 9 日
Hello,
I have a block where I want the unit of the output port to be the same as the Simulink.Parameter (inside a Data Dictionary) that I enter into the mask.
I set the output port unit in the initialization code with:
set_param([gcb '/Out1'], 'Unit', get_param(gcb, 'INPUTPARAM.Unit'));
here INPUTPARAM is the name I assign to the given Parameter in the Mask Dialog and I want to access the Field Unit. Sadly this doesn't work because INPUTPARAM is not the given Parameter but the Value.
So is there a way to access the Unit of the given Simulink.Parameter inside a Data Dictionary in the Mask Workspace?

採用された回答

Fangjun Jiang
Fangjun Jiang 2020 年 9 月 9 日
Yes but it is not very elegant.
"INPUTPARAM" is the name of your mask variable. You have to follow that to get the name of the Simulink.Parameter object, e.g. "MyParam". Then you have to evaluate "MyParam" in base workspace or data dictionary to get a copy of the object, then you can have the "unit" property value.
One trick is to use Simulink.data.evalinGlobal(). It works for both base workspace and Simulink Data Dictionary so you don't have to detect it first.
For Simulink Data Dictionary, there is supposed to be a few API that you can use to access the property value more elegantly. But at the end you still have to make a copy of the object. Since R2018b, I have requested the Mathworks to provide/develop API to access object property value directly. I have not checked the recent versions.
  1 件のコメント
Julius Rauh
Julius Rauh 2020 年 9 月 9 日
編集済み: Julius Rauh 2020 年 9 月 9 日
Thank you very much vor your answer, works perfectly!
I solved it with evalinGlobal like this: (in the mask initialization)
modelname=bdroot;
DDName=get_param(gcb, 'INPUTNAME')
DDEntry=Simulink.data.evalinGlobal(modelname, DDName)
DDUnits=DDEntry.Unit
set_param([gcb '/Out1'], 'Unit', DDUnits);
edit: I forgot that it is possible to promote parameters, instead of the last line it is possible to just promote the Units of the output port (named them Units_out) and write
Unit_out = DDUnits

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAuthor Block Masks についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by