MATLAB Answers

How can I count how many times the position of a bouncing ball on the simulator hits 0?

5 views (last 30 days)
Enzo Amaral
Enzo Amaral on 9 Sep 2021
Edited: Paul on 9 Sep 2021
I'm using MathWorks' sample simulink model for a bouncing ball and I wanted to know if there is any way to calculate how many times the position hits 0 when simulating the model. I'm have just begun using Matlab and Simulink so I'm sorry if it is something obvious. Anyway thanks in advance! (included a printscreen of the model in case anyone wanted to know which one it was)

Answers (1)

Paul
Paul on 9 Sep 2021
Edited: Paul on 9 Sep 2021
Drag a Triggered Subsystem into the diagram.
Connect the output of the <=0 block to the trigger input of the Triggered Subsystem
The inside of the Triggered Subsystem should look like this:
Double click the Memory block, check the box for Inherit Sample Time.
The output of the Triggered Subsystem is the bounce count.
Comment: Initializing the ball at 0 does not count as bounce.

Community Treasure Hunt

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

Start Hunting!