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

54 次查看(过去 30 天)
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.

回答(1 个)

Bego
Bego 2016-9-13
编辑:Bego 2016-9-13
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 个评论
N/A
N/A 2016-9-13
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 2016-9-14
编辑:Bego 2016-9-14
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Choose and Parameterize Blocks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by