How to pause the clock while the simulation continues to run?

1 visualizzazione (ultimi 30 giorni)
I have a model in which I have to compute the distance travelled for a constant speed over the simulation time. However the vehicle makes a number of stops in between during which I do not want the distance to calculate.
Is there a way to pause the clock(input) during these breaks so that I can get the exact distance travelled? The breaks made is given by a binary signal in which (1) is vehicle in running condition and (0) is vehicle in static condition.
My apologies if something similar has been discussed before, however I could not find anything online.
Thanks in advance!

Risposta accettata

Walter Roberson
Walter Roberson il 29 Set 2016
integrate the product of the binary signal and the distance measure. Any time the binary signal is stopped the product will be 0 which will not contribute to the total.
Or if the speed is constant, then integrate the binary signal, and multiply the integral by the constant speed to find the distance traveled.
  2 Commenti
Sujan Dinesh
Sujan Dinesh il 29 Set 2016
Modificato: Sujan Dinesh il 29 Set 2016
The second solution worked, thanks!
If you don't mind, could you please explain what the integrate operator did to the binary signal and how come I didn't need to use time as an input to calculate my distance (constant speed)?
Walter Roberson
Walter Roberson il 30 Set 2016
The situation is like integral of 1 from 0 to t, which is going to return t even though t does not appear in the expression being integrated. Each timeslice of width timestep in which the binary signal is on is going to contribute timestep to the output, and each timeslice of width timestep in which the binary signal is off is going to contribute 0 to the output. That is going to give you timestep times (number of times it was on) as the total. If for example the timestep were 1 second, then the total would be the number of seconds spent traveling.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by