Convert Number of Days to just a number

4 views (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 3 Nov 2022
As it currently exists, ‘B’ is a duration.
Use the days function to convert it to a double-precision number.
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
B = duration
243.93 days
whos B
Name Size Bytes Class Attributes B 1x1 10 duration
B = days(B)
B = 243.9336
whos B
Name Size Bytes Class Attributes B 1x1 8 double
EoT = 9.87*sind(2*B) - 7.53*cosd(B) - 1.5*sind(B)
EoT = 12.4479
.

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!