File Exchange

image thumbnail

Day Length

version 1.3.0.0 (3 KB) by Travis Wiens
Calculates the length of daylight for any day and latitude

8 Downloads

Updated 15 Jul 2015

View License

Calculates the length of daylight for any day of the year and latitude.
This uses Herbert Glarner's formulae which do not take into account refraction, twilight, size of the sun, etc http://herbert.gandraxa.com/herbert/lod.asp.

An example is included

See blog.nutaksas.com for more details/

Comments and Ratings (4)

Mark Brandon

The link to the formula is now at http://herbert.gandraxa.com/length_of_day.xml

xianren

Good!Thanks for sharing.

Chad Greene

This is a helpful function; thanks for sharing.

The input day format is somewhat non-user-friendly. The function header describes the input date as the "day of the year, counted starting with the day of the December solstice in the first year of a Great Year." To maintain Travis' functionality and get this function to work with Matlab's datenum format, add this to the beginning of the function:

if nargin>0 && any(Day>366)
[y,~,~] = datevec(Day);
Day = 11+datenum(Day)-datenum(y,1,1);
end

The above assumes that if any input date exceeds 366, it must be in datenum format. Then the function *approximates* day length assuming a static December solstice. Results will not be exact on the daily timescale, but should be sufficient to put multi-year data in datenum format in context with solar cycles.

good

Updates

1.3.0.0

Fixes bug for latitudes above the arctic circle.

1.1.0.0

Removed GPL per Mathworks' requirements.

1.0.0.0

Mispel Tital

MATLAB Release Compatibility
Created with R2015a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor

day_length_1_03/day_length_1_03/