timer in matlab function
1 次查看(过去 30 天)
显示 更早的评论
Hi, I have some control code in a Matlab function, and I would like to add a timer, that starts when a pump turns on, and if the pump runs for more than x hours continuously, a flag is to be raised, and the timer reset. I am not sure how to implement a timer, or the requested functionality in a Matlab function. I have read about the timer object, but not sure if that is the way to do it. Any suggestions of how to do this, or where to find info ? Thanks Hans Jensen
0 个评论
回答(1 个)
Walter Roberson
2017-6-16
Yes, timer objects run their callbacks when they fire.
However, if by "matlab function" you are referring to "MATLAB Function Block" in Simulink, then you would use a different approach completely, as you would need to look at the simulated time rather than the real time.
2 个评论
Walter Roberson
2017-8-28
Suppose you wanted the flag to be raise after the pump had run for 1 hour. Now, suppose your simulation turns out to be slower than real time, such as if it took 3 minutes real time to simulate each minute of physics: should the flag be raised after 1 hour of real time, or should it be raised after 1 simulated hour? Or perhaps your simulation is faster than life... may it takes only 1 second real time to simulate 6 seconds of pump. Should the flag still be raised after 1 hour of real time, or should it be raised after 1 simulated hour? If you go into the debugger and spend 20 minutes looking around at the state (maybe you went down for coffee while you thought), then should the flag still be raised after 1 real-time hour even if the simulation is paused at the debugger, or should it be after one simulated hour ?
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!