# Reset timer to zero after leaving a state with a transition action

6 visualizaciones (últimos 30 días)
Nathaniel H Werner el 10 de Jun. de 2021
Comentada: Nathaniel H Werner el 15 de Jun. de 2021
I am working on a Stateflow block.
In it I have a state A. In the block, the state A can transition to B, back to A, from A to C, and then back to A.
During the transition from A to B I want to reset the internal clock to zero since there were some other processes happening before but all the interesting stuff starts when going from A to B. I'm also collecting data with a sensor in real time for the entire simulation, so it would be nice to have a final output like this.
t = [0, 0.01, 0.02, ...
T, 0, 0.01, 0.02, ...
];
F = [f(0), f(0.01), f(0.02), ...
f(T), f(T+0.01), f(t+0.02), f(t+0.03),...
];
I'm trying to illustrate that even though the clock reset at t = T, that F keeps on collecting data for each time step before and after until the simulation is done.
EDIT: I forgot to describe what I've done so far.
So far I have simply grabbed the current simulation time upon entering state A for the first time. If there's no way to "restart the clock" then I was simply going to subtract it from the time. It would give some negative times in my array but it would probably work sufficiently well for my case. But I would prefer to "restart the clock".
Is there an easy way to set the clock back to zero? Any tool has to be compatible with the 2016a version of MatLab/Simulink since that's what we use in the lab.
Thanks.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Mark McBroom el 14 de Jun. de 2021
There is no way to reset the simulation time. The approach you are using, which is to get simulation time when the state transition occurs, and then compute delta time based on this captured time and the current time is the best approach.
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Nathaniel H Werner el 15 de Jun. de 2021
OK thanks I wasn't sure, the documentation was confusing to me.

Iniciar sesión para comentar.

### Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

R2016a

### Community Treasure Hunt

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

Start Hunting!

Translated by