How to update programmatically a parameter value in a referenced masked model?

조회 수: 11 (최근 30일)
I have a masked model (let's call it sensor_mdl). Parameters were created in the model workspace as Matlab variables, and set as Arguments. The parameters in the mask refer to the corresponding parameters in the model workspace.
I added this model as a referenced model in another model, called sensor_top, which can contain one or more instances of sensor_mdl.
I am trying to update programmatically the values used for sensor_mdl in sensor_top.
I use the commands:
load_system('sensor_top')
objMask = Simulink.Mask.get('sensor_top/Model');
objMaskParameters = objMask.Parameters;
parameter1 = objMaskParameters(1);
parameter1.set('Value', 1);
But I get the error message:
"Unable to modify the mask of block 'MTM_top/Model'. Modify the referenced model's mask definition instead."
Any idea why and how to fix this?

채택된 답변

Stefanie Schwarz
Stefanie Schwarz 2019년 11월 29일
Hi Nicolas,
editing the Mask object is not the correct workflow. Just use set_param:
set_param('sensor_top/Model','ParamName','1');
HTH,
Stefanie
  댓글 수: 1
Nicolas Oriol
Nicolas Oriol 2019년 12월 2일
Thank you for your answer Stefanie. It does work!
Strange that one has to specify the parameter value as a string though.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Author Block Masks에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by