Modification of variable as a function of time ?

2 次查看(过去 30 天)
Hello,
I am a beginner in simulink and I would like to know how it is possible to modify the value of a variable every second in the following way:
- If variable 1 is 0, do nothing
- If variable 1 is worth 1, increment variable 2 by 300 every second
- If variable 1 is worth 2, decrease variable 2 by 500 every second
Thank you in advance for your help.

回答(1 个)

Amish
Amish 2025-2-13
Hi Louis,
To achieve this in Simulink, you can use a combination of blocks to create a simple model that modifies the value of a variable every second based on the conditions you specified. You will need to have the following blocks in the model:
Constant Block, Integrator Block, Clock Block, Relational Operator Blocks, Switch Blocks, Gain Blocks and a Sum Block.
The connections could be made as follows:
  • Constant block to the input of the Relational Operator blocks.
  • Outputs of the Relational Operator blocks to the control inputs of the Switch blocks.
  • Clock block to the Integrator block to ensure updates occur every second.
  • Outputs of the Gain blocks to the Sum block.
  • Sum block to the Integrator block.
  • Output of the Integrator block to the Scope block for visualization.
You can then set the simulation time, simulate and observe the results.
Additionally, you can use the following documentation for more information on the blocks used:
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Modeling 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by