How Programmatically Edit parameters an Instance of a Masked Simulink Library

3 visualizzazioni (ultimi 30 giorni)
Hey, So I've got a Masked Simulink block that lives in my library, and from that block I am able to call a matlab application by clicking the highlighted text below
Clicking the link opens my matlab application below which simply writes to parameters in the mask
I write to the parameter in the mask using the set parameter command after unlocking the library. My problem is I am editing the mask parameters in the library as oppsed to the instance of the mask being used, hence there is no change to my parametrer(my library parametrer changes though). Question is
  1. how can I retrieve the file path of the Instance being called and change the mask parameter of that instance as opposed to the library,
  2. if I have two instances of the mask in model, how can I differentiate between them, when writing to them from my application.
below is a screen shot of the application code that writes to the parameter.
set_param('FB_Library/voltage in','err_val',num2str(X(app.I(3,1),app.I(3,2))));

Risposte (1)

Ayush
Ayush il 15 Ago 2023
  • In order to retrieve the file path of instance being called and to change the parameter of that instance you can follow the workflow as:
% Get the path of the current block instance
blockPath = gcb;
% Change the mask parameter of the instance
set_param(blockPath, paramName, paramValue);
  • Also, in order to differentiate between the two instances of mask in the model you can use block handle assigned to every block in Simulink model. Here is an example:
% Get the path of the current block instance
blockPath1 = 'model/BlockInstance1'; % path of the first block instance
blockPath2 = 'model/BlockInstance2'; % path of the second block instance
% Retrieve the block handle of the block instances
blockHandle1 = getSimulinkBlockHandle(blockPath1);
blockHandle2 = getSimulinkBlockHandle(blockPath2);
% Change the mask parameter of the block instances based on their UID
if strcmp(targetBlockHandle, blockHandle1 )
set_param(blockPath1, paramName, paramValue1);
elseif strcmp(targetBlockHandle, blockHandle2)
set_param(blockPath2, paramName, paramValue2);
else
error('Invalid block instance');
end

Categorie

Scopri di più su Author Block Masks in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by