How to get system date and time into simulink?

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일

3 개 추천

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

Rick Rosson
Rick Rosson 2012년 2월 28일
eml.extrinsic has been deprecated. The new syntax is coder.extrinsic.
Sathish
Sathish 2013년 6월 24일
In my project, I ve to compare my simulink pattern time and actual time.So i need to get System Date and time. While reading System Date and time, simulink shows the error as
Unsupported: structure access
Function 'Embedded MATLAB Function' (#40.40.53), line 2, column 4: "eml.extrinsic" please help to sort this issue
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일

2 개 추천

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
Rick Rosson 2012년 2월 28일

0 개 추천

Please try using the MATLAB Function block with the code:
function t = sysTime
t = now;
end
HTH.

댓글 수: 5

Jan De Vries
Jan De Vries 2012년 2월 28일
Unfortunately, this doesn't work:
The function 'now' is not supported by Embedded MATLAB for code generation. See the documentation for eml.extrinsic to learn how you can use this function in simulation.
Function 'Embedded MATLAB Function' (#45.25.28), line 2, column 5:
"now"
TAB
TAB 2012년 2월 28일
Try.........
function t = sysTime
eml.extrinsic('now');
t=0;
t = now;
end
Note:
'now' returns the current date and time as a serial date number.
Rick Rosson
Rick Rosson 2012년 2월 28일
Sorry, I forgot to include the extrinsic declaration. Thanks, TAB.
how to call the current time only, not with the current date?
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일

0 개 추천

Thanks all, works perfectly now!
Kareem Abdelgawad
Kareem Abdelgawad 2014년 11월 24일

0 개 추천

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?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Deployment, Integration, and Supported Hardware에 대해 자세히 알아보기

태그

질문:

2012년 2월 28일

댓글:

2023년 12월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by