How can I create a local variable in a simulink model?
48 views (last 30 days)
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.
Bego on 13 Sep 2016
Edited: Bego on 13 Sep 2016
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.