I am beginner to Simulink and had a few experience in Matlab before. My question is the following. Is every Simulink model such as battery,resistor has a special code dedicated to them. For example if i had 2 batteries, do they have different codes such as nominal_voltage1 and nominal_voltage2 that i can change while making simulation if a certain voltage level exceeds?

enter image description here

  • \$\begingroup\$ Placing a component like a battery in Simulink just means you just insert a certain routine (procedure) which describes a battery. A 2nd battery of course needs the same procedure, the same code. It is still a battery ! The difference is that you can set the first battery to voltage 1 and the second to voltage 2. They will not influence each other, that would be stupid. It is the same as you using a function or procedure while programming in whatever language. The procedure/function remains the same while you can use it multiple times each time using it with different variables. \$\endgroup\$ Aug 22, 2017 at 8:51
  • \$\begingroup\$ Thank you for your answer. I understand what you mean. How can i acccess these variables in Matlab code? \$\endgroup\$ Aug 22, 2017 at 9:22
  • \$\begingroup\$ What variables ? All variables in MatLab are assigned by your code either you write the code yourself or use Simulink blocks which have inputs and parameters. These set the values of the variables. Matlab is basically a program which works on sets of data. This data is in the variables. \$\endgroup\$ Aug 22, 2017 at 9:26
  • \$\begingroup\$ Okey then my question is the following. How can i set the voltage of a battery to 0 while not affecting other. Which Simulink block should is use? That is what i mean by accesing variables. \$\endgroup\$ Aug 22, 2017 at 9:36

1 Answer 1


Each configurable block in simulink can be configured with a unique or common variable.

Below is a simple workspace with 5 constant block. The constant block was chosen because the block mask updates with the configured variable.

Constant is set to 1 Constant1 is set to 10 Constant2 is set to variable foo Constant3 is set to variable foo Constant4 is set to variable bar

The variables foo and bar can be set in the matlab workspace OR via a datadictionary. because constant2 and constant3 use the same variable they will output the same constant.

This is the same for all configurable blocks so you can easily add two batteries and configure each one with a value of nominal_voltage1 & nominal_voltage2, set these two variables in the matlab workspace (say via an m-file) and they will be independent.

As to underlying code... Simulink is proprietary, they do not show you the code. The Simscape area does use their new scripting language for physics base calculations and a lot of those blocks have viewable source enter image description here

  • \$\begingroup\$ Thank you for your detailed answer. I try to do the things you said but i had a small problem. I do not understand what to do after assiging a variable in the simulink. It can be seen on the question which i edited to post picture. \$\endgroup\$ Aug 30, 2017 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.