Modifying a Simulink model mask from a Matlab app, built in App Designer.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Paul
el 3 de Feb. de 2024
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!
0 comentarios
Respuesta aceptada
Ayush Singh
el 13 de Feb. de 2024
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 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Subsystems en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!