MATLAB Answers

One of the Mask Parameters getting reset in Entire Model while saving Custom Library.

17 views (last 30 days)
Agam Srivastava
Agam Srivastava on 9 Apr 2021 at 13:28
Answered: Fangjun Jiang on 13 Apr 2021 at 20:46
I have created a masked subsystem which has three fields:
  1. Edit field to choose data dictionary name. Based on this selection, the masked block reads the dictionary and finds out all the enumerations present in the dictionary.
  2. First Popup to list all Enumerations found in data dictionary [Populates Based on callback added in Edit field] and make selection as per User Click. (Variable name --> enum_datatype)
  3. Second Popup to create list of values based on Enum Selection made in First Popup [Populates Based on callback added in First Popup]. (Variable name --> enum_params)
First Popup is then used to write Output Datatype of a Constant block and its Value (of constant block) is written from Second Popup.
This is working fine and masked subsystem is able to update underlying Constant block as per selections done. I have made it a custom library for my model and using it at many places then.
However while saving custom library, First Popup variable (enum_datatype) still holds its values but Second Popup variable (enum_params) resets itself. Due to this in model, wherever this block is used, second variable (enum_params) in all of them gets reset. This happens also while compiling the model.
I have tried debugging the Mask initialization code and variable is resetted even before Mask Initialization has been called. I have also tried checking all attributes and they all are set to "Evaluate, Tunable, Enable and Visible". Remaining attributes like "Read Only, Hidden and Never Save" are not ticked.
Please help me on getting solution for this! I am not sure what is resetting it.
Thanks in advance.

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 13 Apr 2021 at 20:46
Things like this usually gets complicated when it is put in a library.
Without the actual model, I could guess:
  1. If you are setting the Constant block value using set_param() based on the selection in second Popup, then this is the wrong implementation if you want to put it in a libarary. Instead, you should set the value of the Constant block as "Pop2" and name the parameter for the second Popup as "Pop2". In other word, pass the masked parameter to the Constant block.
  2. If you have to use set_param() to set the value of the Constant block, then you need to add a callback to the CopyFcn of the library block, which will automatically disable the library link once the block is dropped to the model. This is not ideal because all the library links will be broken. But it had to be done if all the blocks dropped to the model end up differently due to set_param(). Remember, all the blocks in the model are supposed to be an exact copy of the library block except the allowed parameters. If your blocks in the model end up diffrently due to the selection in Popup in the mask, then you have a problem and you have to deal with it accordingly.
  3. Look for "Parameterized Links and Self-Modifiable Linked Subsystems" in the document. I believe your issue stems from this topic. Option 1 and 2 above are easy solutions if they are acceptable. This document should provide full details.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!