how to access the variable value declared in constant block using get_param command.

how to access the variable value declared in constant block using get_param command.
------------------------------------------------------------------------------
initially i declared value for a is 1 in work space.
normally i access the variable by following way,
get_param(gcb,'value')
for above command i got the following answer, ans= a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
but, i want to get the ans is 1
how to use get_param() command to access the value 'a' stored in workspace.
i attached the screen shot of that simulink model ----------------------------------------------------------------------------------

 採用された回答

stozaki
stozaki 2020 年 1 月 12 日
Hello Ravi,
Did you solve this problem? Please try following script.
a = 1; % define the value of 'a'
blkValue = get_param(gcb,'Value'); % get the constatn value as Parameter.
value = evalin('base',blkValue); % evaluate value in the base workspace.
Regards,
stozaki

3 件のコメント

Ravi
Ravi 2020 年 1 月 12 日
Hello stozaki,
Thanks for your answer. Can you please tell me how to access Parameter defined in Model Workspace?
Kindly find the below image for more details,
1) Base Workspace
ModelWorspace.JPG
Hello Ravi,
If you use model workspace, please try following script.
a = 1; % define the value of 'a'
blkValue = get_param(gcb,'Value'); % get the constatn value as Parameter.
mdlWks = get_param(gcs,'ModelWorkspace'); % get model workspace object
Prm = evalin(mdlWks,blkValue); % evaluate value in the base workspace.
If you use Simulink.Parameter, Please get the property of the value that was got last.
valueOfParameter = Prm.Value;
Regards,
stozaki
Ravi
Ravi 2020 年 1 月 12 日
Thanks, It's working fine.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeProgrammatic Model Editing についてさらに検索

質問済み:

2017 年 8 月 19 日

コメント済み:

2020 年 1 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by