How can I create a local variable in a simulink model?

51 visualizaciones (últimos 30 días)
N/A
N/A el 12 de Sept. de 2016
Editada: Bego el 14 de Sept. de 2016
Hello I am working on modeling an electric motor using simscape blocks, the model includes resistances, inductances and voltage sources. The parameters of these blocks change with time, so for example I can't type a constant numeric value in the inductance block dialog. I have thought of giving the name "L", a varable, for the value of the inductance in the dialog. Is there a way of making "L" a local variable for the model? not a variable in the mat-lab workspace. I intend to duplicate that model a number of times for a bigger model, and it would be difficult to change the name of each variable in each model, and I wouldn't want the models to overwrite each other in the mat-lab workspace during simulation. Thank you.

Respuestas (1)

Bego
Bego el 13 de Sept. de 2016
Editada: Bego el 13 de Sept. de 2016
Hello Mustafa,
I am unaware of a specific component to define local variables in Simulink.
However, I would recommend to create an 'Initial_Configuration_Function.m' for each of your models (This file is intended to store all the local configuration of each model). So that this function can be added at the very begining of your Simulink diagram using a 'MATLAB Function' block. This way everytime your model runs, it will demux all of the outputs of 'Initial_Configuration_Function.m' and send them to their corresponding usages.
For example In the code below, my Initial_Configuration_Function is called Control.m. This function calculates a total of 9 control variables that are used across the application. The output variable are sent at the end of the function.
Later, on the Simulink Diagram this function is added as a function block. In order to retrieve all data, a DEMUX component is used to extract all variables (which eventually are sent all across the application).
As you can see, Control.m is sending 9 items and the demux is retrieving all of them:
Hope this helps.
Regards,
  2 comentarios
N/A
N/A el 13 de Sept. de 2016
Hello Sir I appreciate your help. I tried your answer on a simple system to test the concept, but even if I use an interpreted mat-lab function, how would I pass a parameter from the function or demux to the resistance block?
Bego
Bego el 14 de Sept. de 2016
Editada: Bego el 14 de Sept. de 2016
I see the problem now.
I'm not familiar with electric or simscape blocks but for the little I've read, it seems that it is not possible to change the value of the R/C/L parameters during the simulation, since Matlab calculates all the equations for the system after startup. Therefore, instead of using a fixed ' Resistor ' block you should use a ' Variable Resistor ' block.
If that doesn't work, have a look at the following example: Variable Inductance Modeling Example
Hope this helps.
P.S. A better title for this question should have been something like: how to set a resistor with variable resistance?

Iniciar sesión para comentar.

Categorías

Más información sobre Choose and Parameterize Blocks en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by