Modification of variable as a function of time ?

5 vues (au cours des 30 derniers jours)
Louis Cod
Louis Cod le 1 Jan 2020
Réponse apportée : Amish le 13 Fév 2025
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.

Réponses (1)

Amish
Amish le 13 Fév 2025
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!

Catégories

En savoir plus sur Modeling dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by