How to get system date and time into simulink?

41 vues (au cours des 30 derniers jours)
Jan De Vries
Jan De Vries le 28 Fév 2012
Commenté : Srikar le 11 Déc 2023
Is there a way to get the system date and time (not simulation time) into simulink?
  2 commentaires
TAB
TAB le 28 Fév 2012
In which datatype & formate?
How you are going to use it in simulink?
Jan De Vries
Jan De Vries le 28 Fév 2012
As integers, I'm going to use it to calculate the position of the sun (which depends on location and date/time).

Connectez-vous pour commenter.

Réponse acceptée

TAB
TAB le 28 Fév 2012
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 commentaires
Kaustubha Govind
Kaustubha Govind le 24 Juin 2013
Sathish: Please post this as a new question along with your code.
Srikar
Srikar le 11 Déc 2023
Can the new question's link be shared here, it shall help out many!

Connectez-vous pour commenter.

Plus de réponses (4)

Rick Rosson
Rick Rosson le 28 Fév 2012
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 commentaire
macs macalintal
macs macalintal le 1 Mar 2016
it says error, too many output arguments, help pls

Connectez-vous pour commenter.


Rick Rosson
Rick Rosson le 28 Fév 2012
Please try using the MATLAB Function block with the code:
function t = sysTime
t = now;
end
HTH.
  5 commentaires
macs macalintal
macs macalintal le 7 Mar 2016
how to call the current time only, not with the current date?
Walter Roberson
Walter Roberson le 7 Mar 2016
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.

Connectez-vous pour commenter.


Jan De Vries
Jan De Vries le 28 Fév 2012
Thanks all, works perfectly now!

Kareem Abdelgawad
Kareem Abdelgawad le 24 Nov 2014
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 commentaires
shu
shu le 22 Jan 2015
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 le 13 Août 2019
I have also encountered that problem. Is there any solutions?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Deployment, Integration, and Supported Hardware dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by