Sun Position

Version 2.0 (136 KB) by Jeff Dozier
Contains functions for declination, solar longitude, radius vector, equation of time, times of sunrise and sunset, sun angles and azimuths.
Updated 25 Jun 2021

View License

Uses the distance function from the MATLAB Mapping Toolbox to calculate the arc distance to the sub-solar location. Includes checkSizes function from my general function library.
EarthEphemeris - Returns the solar declination, Earth-Sun radius vector (distance in astronomical units), solar longitude, and optionally the equation of time.
sunang - Returns cosine of sun angle, its azimuth (0 south, + east), and airmass (path length accounting for Earth curvature). Optionally accounts for refraction.
sunRiseSet - Times of sunrise and sunset.
sunslope - Cosine of illumination angle on slope

Cite As

Jeff Dozier (2024). Sun Position (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2021a
Compatible with R2014b and later releases
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Inspired: Topographic Horizons

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes

cleaned up internal folder structure


MATLAB functions calculate azimuths clockwise from North. My convention has been to use counter-clockwise from south, positive east, negative west. I added a function to let the user choose which convention to use.


No change in the code. Added an image showing the Global Daylight example.


Updated one of the examples


uploaded correct version


removed call to today(), I didn't realize it was in the Financial Toolbox, thanks to Christie for reminder to use clock() instead. Also fixed a glitch in PlotSolarPath.