Countdown timer continuously running

4 ビュー (過去 30 日間)
Cary
Cary 2015 年 9 月 10 日
回答済み: Tim Jackman 2015 年 9 月 14 日
I am trying to figure out the best approach to this so I appreciate your thoughts. I'm running a model that uses the number of minutes remaining as an input. Let's say it counts down to September 30th. So as of right now there is roughly 21*24*60 = 30,240 minutes remaining. The time remaining should decrease every second. How can I achieve this? Some sort of endless loop? Part of a script? Or a function? Keep in mind this is only one input in my model, and there are many other moving parts. What type do I want...a datetime array? That is what I have been working with so far.

回答 (1 件)

Tim Jackman
Tim Jackman 2015 年 9 月 14 日
I'd recommend using a timer object. You can set it to execute a callback function every second. Within that callback function, you can update your countdown variable. It seems like the thing to try first in your scenario. Here are a couple links that include a basic example on how timer objects work:
As for your question about what data type to use, a datetime array should be fine. Alternatively, you could convert the datetime into the number of minutes or seconds remaining if that is all you need from this variable. Hope this helps.

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by