Convert Number of Days to just a number
4 views (last 30 days)
Show older comments
Nathan Liscouski
on 3 Nov 2022
Commented: Star Strider
on 3 Nov 2022
I'm doing a lot of operations on day and time for some solar position calculations. In doing so I have a decimal day value which is a day + a duration (ex. 328.32 days).
I need to use this value in calculations and as inputs to trig functions in degrees- but in trig functions I get:
Check for incorrect argument data type or missing argument in call to function 'sind'.
Error in AngleSimulation (line 27)
EoT = 9.87*sind(2*B) - 7.53*cosd(B) - 1.5*sind(B);
I am trying to convert the day value to just a number so I can use it in those equations.
Code here- relevant variable is "d"
%%inputs
date = "24/11/2023"; %DD/mm/yyyy
time = "14:43"; %'hh:mm' from 00:00-24:00
timezonedif = "-07:00"; %"+-00:00 from UTC"
long = -105.944183;%degrees East or - degrees West
lat = 35.691544;%degrees North or - degrees south
%%converting inputs
date = datetime(date, "InputFormat","dd/MM/uuuu");
time = duration(time, 'InputFormat', 'hh:mm', 'Format', 'h');
timezonedif = duration(timezonedif, 'InputFormat', 'hh:mm');
UTCtime = time + timezonedif;
UTCtimedayfrac = duration(UTCtime, 'Format', 'd');
%%finding day
d = day(date, "dayofyear") + (UTCtimedayfrac);
%%finding hour angle
%local standard time meridian
LSTM = 15 * UTCtime; %degrees
%equation of time
B = 360/365*(d - 81);%degrees
EoT = 9.87*sind(2*B) - 7.53*cosd(B) - 1.5*sind(B);
%time correction factor
TC = 4*(long - LSTM) + EoT;
%local solar time
LST = time + TC/60
%hour angle
0 Comments
Accepted Answer
Star Strider
on 3 Nov 2022
As it currently exists, ‘B’ is a duration.
Then, it works —
date = "24/11/2023"; %DD/mm/yyyy
time = "14:43"; %'hh:mm' from 00:00-24:00
date = datetime(date, "InputFormat","dd/MM/uuuu");
time = duration(time, 'InputFormat', 'hh:mm', 'Format', 'h');
timezonedif = "-07:00"; %"+-00:00 from UTC"
timezonedif = duration(timezonedif, 'InputFormat', 'hh:mm');
UTCtime = time + timezonedif;
UTCtimedayfrac = duration(UTCtime, 'Format', 'd');
d = day(date, "dayofyear") + (UTCtimedayfrac);
B = 360/365*(d - 81) %degrees
whos B
B = days(B)
whos B
EoT = 9.87*sind(2*B) - 7.53*cosd(B) - 1.5*sind(B)
.
2 Comments
More Answers (0)
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!