How to get system date and time into simulink?
83 次查看(过去 30 天)
显示 更早的评论
Is there a way to get the system date and time (not simulation time) into simulink?
2 个评论
采纳的回答
TAB
2012-2-28
Use below code in embedded matlab function block. It will give the date and time components as separate output.
function [Y, M, D, H, MN, S] = fcn()
eml.extrinsic('now');
eml.extrinsic('datevec');
Y = 0;
M = 0;
D = 0;
H = 0;
MN = 0;
S = 0;
[Y, M, D, H, MN, S] = datevec(now);
end
4 个评论
更多回答(4 个)
Rick Rosson
2012-2-28
A slightly simpler version:
function [Y, M, D, H, MN, S] = sysClock()
coder.extrinsic('clock');
Y = 0;
M = 0;
D = 0;
H = 0;
MN = 0;
S = 0;
[Y, M, D, H, MN, S] = clock;
end
Rick Rosson
2012-2-28
5 个评论
Walter Roberson
2016-3-7
There is no way to fetch only the time without the date. The sysClock routine that Rick showed above can be modified to discard the date portions and return only the time components.
Kareem Abdelgawad
2014-11-24
I tried to use it under 'Real-Time Windows Target', but it doesn't work. Any ideas how to read system time under 'Real-Time Windows Target'?
2 个评论
shu
2015-1-22
Me too. With the error of "The extrinsic function 'clock' is not available for standalone code generation. It must be eliminated for stand-alone code to be generated."
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!