How to associate a set of parameters to a subsystem

3 visualizzazioni (ultimi 30 giorni)
Stephane
Stephane il 5 Dic 2018
Risposto: Gayathri il 13 Feb 2025
I have a model "M" with 2 subsystems M/C1 and M/C2.
C1 and C2 are identical, with same parameter name llist.
Q : How to associate a parameter set from mfile Tun1.m for C1 and Tun2.m for C2 ?
I have tried :
Solution 1 :
  1. load Tun1 and Tun2 in a structure
  2. create a mask on the subsystem
  3. set structure Tun_x in the mask
  4. In the mask inititalisation for each file a of the structure vari = Tun_x.vari
It works for simulation but we can't compile "M" because we can't set tunable structures for compilation. And init of subsystem are not included for compilation.
Solution 2 :
With data dictionary
I need to create 2 reference models for C1 and C2 to associate my data dictionaries.
Then when I simulate "M", I have conflict names between Tun1 and Tun2.
Solution 3 :
Rename automatically all parameters in the subsystem (more than 1000) with a prefix.
How to find all parameters list with block path and property in order to modify with a set_param ?
Does somebody have an idea to solve my issue ?
Thank you

Risposte (1)

Gayathri
Gayathri il 13 Feb 2025
To load a set of parameters with same name but different values for two subsytems, first you need to create a mask for both of the subsytem. Ensure that the parameter files "Tun1.m" and "Tun2.m" are correctly defined and accessible from the MATLAB path. When creating a mask for each subsystem, make sure the initialization code is correctly set up to load the parameter files. Then, we should assign the values loaded to the parameters in the block using the "set_param" function.
Please refer to the below code that has to be added to the initialization callback of the mask.
function MaskInitialization(maskInitContext)
run("Tun1.m")
set_param("untitled2/Subsystem/Gain",'Gain',num2str(G1));
set_param("untitled2/Subsystem/Constant",'value',num2str(C1));
end
I had created a dummy model with a "Constant" and "Gain" block to try out this task. The "Mask Editor" window for assigning the constant and gain values for the corresponding blocks would look like the screenshot attached below.
Similarly, perform the same for the other subsystem as well.
Please use the below command to learn more about the "set_param" function.
doc set_param

Categorie

Scopri di più su Subsystems in Help Center e File Exchange

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by