time increment and julian date
Afficher commentaires plus anciens
Hello everyone,
Here is my problem:
First I have a departure date:
date_ = ( 2011 08 18) % initialize
Let's say I have a loop as well, and within this loop I need to convert from calendar date to Julian date since I am using this information later to determine the geocentric position of the Sun rsun_.
For t = 0 : 30 min : 200 days % 200 days is the simulation time
date_ = date_ + t_; % how to add 30 minutes for each iteration and
keeping format (YYYY MM DD) for conversion to
Julian date
date__ = julian( date_ );
rsun_ = ephemeris_sun( date__ );
% after I can perform my calculations
My problem is: look comment in the loop.
Thanks a lot,
Rom
Réponse acceptée
Plus de réponses (2)
James Tursa
le 7 Juil 2011
0 votes
Caution: To be precise, a sun position algorithm will need a Julian Date based on Ephemeris Time. So you would need to convert the date vector from whatever time convention it is in (e.g., your local time, or UT, or whatever) to an Ephemeris Time before doing the Julian Date conversion. Basically, planetary calculations need a continuous time to work with, and local times, UT, etc do not meet that requirement. What time convention is your date vector in?
Argiris
le 31 Août 2022
following is a code that increases the time every 10 seconds and has an output a table A=[YY,MM,DD,HH,MM,SS].
You can then easily manipulate the matrix to any spesific form by combining stings and variables.
e.g
A(1)+"/"+A(2)+"/"+A(3)+" "+A(4)+":"+A(5)+":"+A(6)
time= [2022,1,1,0,0,0]; %Initiallize time and date
c=0;
c1=0;
c2=0;
c3=0;
c4=0;
j=0;
time_increment=10; %time increment in seconds
for i=0:65000
if time(6)<=60
time(6)=time(6)+time_increment;
c=c+1;
end
if time(6)>=60
time(6)=0;
time(5)=time(5)+1;
c=0;
c1=c1+1;
end
if time(5)>=60
time(5)=0;
time(4)=time(4)+1;
c1=0;
c2=c1+1;
end
if time(4)>=24
time(4)=0;
time(3)=time(3)+1;
c2=0;
c3=c3+1;
end
if time(3)>=12
time(3)=0;
time(2)=time(2)+1;
c3=0;
c4=c4+1;
end
j=j+1;
A(j,1)=time(1);
A(j,2)=time(2);
A(j,3)=time(3);
A(j,4)=time(4);
A(j,5)=time(5);
A(j,6)=time(6);
end
1 commentaire
Rather than doing the date and time arithmetic yourself, just let datetime handle it.
startTime = datetime(2022,1,1)
Let's say that I want ten date and time values spaced 10 minutes apart, starting at startTime.
increments = (0:9).'*minutes(10);
theTimes = startTime + increments
If we wanted Julian dates:
format longg
theJulianDates = juliandate(theTimes)
Catégories
En savoir plus sur Calendar dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!