How to use parameters that are defined in one subsystem in another subsystem?

14 visualizaciones (últimos 30 días)
Shyam
Shyam el 15 de Mayo de 2013
Respondida: Gayathri el 6 de Feb. de 2025 a las 7:16
I have defined a parameter, Jm in one subsystem, i want to add this to another parameter defined in another subsystem and use the sum in a gain block in the latter subsystem.
Any ideas or suggestions, pls post
Thanks
  1 comentario
Kaustubha Govind
Kaustubha Govind el 15 de Mayo de 2013
Could you explain what you mean by defining parameters in a subsystem? Is 'Jm' really an output of the subsystem, or is it really the value of a dialog parameter that is defined in the subsystem's Mask Workspace?

Iniciar sesión para comentar.

Respuestas (1)

Gayathri
Gayathri el 6 de Feb. de 2025 a las 7:16
Hi @Shyam,
I understand that you want to use a variable defined in the mask of one subsystem within another subsystem. I have created a simple Simulink model with two subsystems, wherein a constant block in the 2nd subsytem needs the value of a variable defined in the mask of the 1st subsystem.
To perform this operation, "assignin" function can be used in the model initialization callback to register a variable in the base workspace with the value of the entered mask parameter. The Constant block can then successfully take its value from the workspace variable (independent of the subsystem scope).
I have initialised a parameter G in the mask of the first subsystem. To retrieve the value of this variable please use the below lines of code in the "InitFcn" tab of Model Callbacks section.
value = get_param('untitled2/Subsystem', 'G');
value = str2double(value);
assignin('base', 'G', externalConstValue);
The mask values are taken in as "char" and since that is not accepted as a valid value to the Constant block, it has been converted to double using "str2double". This code writes a variable 'G' into the base workspace, which can then be used by the other subsystem.
For more information on the "assignin" function, please refer to the below documentation link.
Hope you find this information helpful!

Categorías

Más información sobre Subsystems en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by