Modifying a Simulink model mask from a Matlab app, built in App Designer.

조회 수: 7 (최근 30일)
Paul
Paul 2024년 2월 3일
편집: Paul 2024년 2월 20일
In Simulink, I have built a subsystem block with a mask, which includes a 'popup' mask entry, allowing the user to set a parameter to 'on' or 'off'. I now want to write to this parameter from a Matlab app, using, for example, the simulink.compiler.modifyParameters command, not the set_param command, because I want to deploy the app.
In the documentation for simulink.compiler.modifyParameters, examples are given to modify an 'edit' parameter in a mask, e.g.:
if time==5.0
% Modify global variables used by top model gain block
newGlobalVars = [Simulink.Simulation.Variable('gNum',1.1),...
Simulink.Simulation.Variable('gDen',0.5)];
simulink.compiler.modifyParameters(model,newGlobalVars);
end
However, this won't work for a 'popup' mask entry. How can I use simulink.compiler.modifyParameters to achieve this? For example, would:
parameterPath = [modelName '/' subsystemName '/' parameterName]
newParam_popup = struct(parameterPath, 'off');
simulink.compiler.modifyParameters(model, newParam_popup);
work i.e. writing directly to the mask path, not requiring the parameter to be set as a global or model workspace variable?
Thanks for any help provided!

채택된 답변

Ayush Singh
Ayush Singh 2024년 2월 13일
Hi Paul
As per the use of 'simulink.compiler.modifyParameters' , it does not directly modify mask parameters by specifying the block path and parameter name in the way you have described.
Instead, the function is designed to modify variables in the base workspace, model workspace, or as global parameters that are then linked to block parameters within the model.
Try using the following code to modify the 'popup' mask entry
% Name of Simulink model
modelName = 'your_model_name';
% Name variable linked to your mask parameter
parameterName = 'popupVar';
% The new value you want to set ('on' or 'off')
newValue = 'off';
% Create a Simulink.Simulation.Variable object with the new value
newParamVar = Simulink.Simulation.Variable(parameterName, newValue);
% Modify the parameter using simulink.compiler.modifyParameters
simulink.compiler.modifyParameters(modelName, newParamVar);
I hope the above information helps.
  댓글 수: 1
Paul
Paul 2024년 2월 20일
편집: Paul 2024년 2월 20일
Hi Ayush,
Thanks for the response.
In the end I replaced mask 'popup' entries with 'edit' entries i.e. so my app could write to scalar values and not strings, which works fine with the 'simulink.compiler.modifyParameters' command i.e. as shown in the example: https://uk.mathworks.com/help/slcompiler/ref/simulink.compiler.modifyparameters.html
I believe however, there is a bug when trying to write vectors to a variable from an app, Again, as a workaround, these entries need to be broken down into scalars to allow 'simulink.compiler.modifyParameters' to work. The bug has been reported and I believe will be fixed in a future release.
Finally, if the variables are used to define transfer function coefficients, then compilation fails. The workaround here is to deconstruct the transfer function into a feedback loop using gain blocks and integrators, the allow scalar values to be written from an app.
Regards,
Paul.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subsystems에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by