Convert time string to 24 hour format then into Decimal using current time clock

I am trying to convert the variable AST from a string to a number in 24 hour format. I would then like to store AST as a new variable, call it 'ASTdec' in decimal i.e AST at 13:30 = 13.5 so that I can manipulate it with other eqns. AST is the solar time, converted from regular clock time.
background code:
c = clock();
tsNow = datenum(c);
tsStart = datenum([c(1) 1 1 0 0 0]);
daysInYear = tsNow - tsStart;
DayOfYear = floor(daysInYear)+1;
get current LST time in 24 hour format:
datestr(now);
d = rem(now,1);
datestr(d);
time = datestr(d, 'HH:MM');
get apparent solar time AST:
B = 360/365*(DayOfYear-81);
EoT = 9.87*sind(2*B)-7.53*cosd(B)-1.5*sind(B);
Correction = EoT - (4*(0-3.173));
Declination = 23.45*sind((360/365)*(284+DayOfYear));
AST = datestr(d - datenum([0 0 0 0 Correction 0]));
Tried using:
ASTVec = datevec(AST, 'HH:MM');
SolarMinutes = ASTVec(5);
SolarHours = ASTVec(4);
to get the vector and then do manipulation with the vector cells to get my decimal but SolarHours are not in 24 hr format because the string is not in 24 hour format. Variable
Correction
is already a value of time expressed in decimal and is used to define AST.

 채택된 답변

It looks to me like,
ASTVec = datevec(d - Correction/(24*60));

댓글 수: 3

Sorry but I don't see how this helps. I want to store the 24 hour format of AST string as a number so that it can be passed to SolarMinutes and SolarHours in 24 hour format. The line of code you quoted just gives a new datevec with the time inc seconds as a vector.
Minutes if I have correctly understood your Correction to be in minutes. You would continue on with your existing code,
SolarMinutes = ASTVec(5);
SolarHours = ASTVec(4);
Got it. Because I wasn't actually in 24 hour time when running the script I wasn't sure I was getting the correct answer. Thank you.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Time Series Objects에 대해 자세히 알아보기

질문:

P
P
2013년 11월 15일

댓글:

P
P
2013년 11월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by