How to get system date and time into simulink?

113 ビュー (過去 30 日間)
Jan De Vries
Jan De Vries 2012 年 2 月 28 日
コメント済み: Srikar 2023 年 12 月 11 日
Is there a way to get the system date and time (not simulation time) into simulink?
  2 件のコメント
TAB
TAB 2012 年 2 月 28 日
In which datatype & formate?
How you are going to use it in simulink?
Jan De Vries
Jan De Vries 2012 年 2 月 28 日
As integers, I'm going to use it to calculate the position of the sun (which depends on location and date/time).

サインインしてコメントする。

採用された回答

TAB
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 件のコメント
Kaustubha Govind
Kaustubha Govind 2013 年 6 月 24 日
Sathish: Please post this as a new question along with your code.
Srikar
Srikar 2023 年 12 月 11 日
Can the new question's link be shared here, it shall help out many!

サインインしてコメントする。

その他の回答 (4 件)

Rick Rosson
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
  1 件のコメント
macs macalintal
macs macalintal 2016 年 3 月 1 日
it says error, too many output arguments, help pls

サインインしてコメントする。


Rick Rosson
Rick Rosson 2012 年 2 月 28 日
Please try using the MATLAB Function block with the code:
function t = sysTime
t = now;
end
HTH.
  5 件のコメント
macs macalintal
macs macalintal 2016 年 3 月 7 日
how to call the current time only, not with the current date?
Walter Roberson
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.

サインインしてコメントする。


Jan De Vries
Jan De Vries 2012 年 2 月 28 日
Thanks all, works perfectly now!

Kareem Abdelgawad
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
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."
Wenbin Xu
Wenbin Xu 2019 年 8 月 13 日
I have also encountered that problem. Is there any solutions?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by