How can I change the values of edit boxes in a mask?

8 ビュー (過去 30 日間)
Malte Otten
Malte Otten 2019 年 9 月 23 日
編集済み: Malte Otten 2019 年 10 月 2 日
Hallo,
I was wondering how to change the values in the edit boxes of simulink block mask. If I understood the following Answer right, this is not possible: https://de.mathworks.com/matlabcentral/answers/98264-why-am-i-unable-to-change-the-default-value-of-a-block-parameter-using-the-set_param-function-in-sim
I would be really happy, if anyone can show me a way to get this done.
Greetings
  4 件のコメント
Renato SL
Renato SL 2019 年 9 月 23 日
Maybe this reference could help.
I never need to set values of mask parameters programmatically, so I'm not sure what to do.
Perhaps you can give a variable name inside the mask, for example in Cultivator block, you give "value1" as a mask parameter value. Then, in the script, you specify
value1 = 10; %for example
I think that can work, but I don't know if that is what you need.
Malte Otten
Malte Otten 2019 年 9 月 23 日
I took a screenshot from my mask. Maybe this will make it easier. ScreenshotMask.PNG
If I type in the following code, I get the following error message:
>> Simulink.MaskParameter.set(BC,1)
Undefined function or variable 'BC'.

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

採用された回答

Fangjun Jiang
Fangjun Jiang 2019 年 9 月 23 日
Just use
get_param(gcb,'BC')
set_param(gcb,'BC','1');
  8 件のコメント
Malte Otten
Malte Otten 2019 年 9 月 26 日
Hey, thank you for your help ! This works great!
Malte Otten
Malte Otten 2019 年 10 月 2 日
編集済み: Malte Otten 2019 年 10 月 2 日
I have now applied the changes to the code but I get another problem. If I use more than one of these statements in the initialization script, e.g.
open_system('Testframe_with_Cultivator_mounted');
% Open the mask of the block
blk='Testframe_with_Cultivator_mounted/Cultivator';
% Set values in the edit boxes of the mask
set_param(blk,'BC',num2str(Mdl.implement.Cultivator.BC));
set_param(blk,'h_S1',num2str(Mdl.implement.Cultivator.h_S1));
it will only change the value in box BC. The value in box h_S1 will not be changed when running the script. Both BC and h_S1 are in the same tab and the I have already checked the name of the boxes to ensure that they are right.
Do you have any suggestion on solving this problem?

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by