Is it better to use tic/toc or a timer function for tracking time?
10 ビュー (過去 30 日間)
古いコメントを表示
I am using MATLAB App Designer to make a GUI to read data coming in from an arduino. I want to assign timestamps to incoming data to use for graphing it live, and I am wondering whether it is better to use a timer function or tic/toc? I am mostly asking for performance reasons, it's a rather complex application and I don't want to add any more execution time or whatnot that I can avoid.
0 件のコメント
採用された回答
Steven Lord
2025 年 2 月 10 日
If you want to retrieve the current time, use:
dt = datetime('now')
To retrieve it as text data:
s = string(dt)
Depending on how you want the time represented (Different time zone? Different display format?) you may need to add other options from the datetime documentation page.
dt = datetime('now', TimeZone="America/New_York")
dt = datetime('now', Format="dd/MM/yy hh:mm:ss a")
The tic and toc functions are for measuring elapsed time, and timer schedules when commands should be executed.
3 件のコメント
Voss
2025 年 2 月 10 日
Note that elapsed time can be found by taking the difference of two datetimes, which is a duration (which is suitable for graphing/plotting).
t_start = datetime('now')
pause(3)
t_now = datetime('now')
delta_t = t_now - t_start
Steven Lord
2025 年 2 月 10 日
t_start = datetime('today')
t_now = datetime('now')
delta_t = t_now - t_start
fprintf("It is now %g seconds or %g minutes or %g hours since midnight.", ...
seconds(delta_t), minutes(delta_t), hours(delta_t))
[h, m, s] = hms(delta_t);
fprintf("It has been %d hours, %d minutes, and %g seconds since midnight.", ...
h, m, s)
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!