# How to calculate mean wind direction

99 views (last 30 days)
Jenna Marie on 5 May 2014
Commented: Walter Roberson on 5 Aug 2020
Hello!
I need help figuring out how to calculate mean wind direction when my data is in degrees (0-360). I just realized my current program does not take into account that the data is circular, and the mean of 355 and 5 will be 180, instead of 0. Any help is greatly appreciated! I am a beginner when it comes to MATLAB programming
##### 2 CommentsShowHide 1 older comment
Jenna Marie on 5 May 2014
Ah yes thank you for catching that! Accidentally mixed up 360 degrees in a circle with 365 days in a year. It's been a long day....

José-Luis on 5 May 2014
average = mod(sum(data),360)./numel(data)
Walter Roberson on 5 Aug 2020
The below version handles arrays.
function [windir_avged] = windir_avg(windir)
windir_avged=180/pi*angle(sum(exp(1i.*windir.*pi/180))/numel(windir));
mask = windir_avged<=-0.001; %it should be 0 but the it would inclde some slightly negative numbers that are just due to numerical precision
end

Jenna Marie on 5 May 2014
Thank you so much for your response!
What does numel mean?
José-Luis on 5 May 2014
No worries.
doc numel
Counts the number of elements in the matrix.

Walter Roberson on 9 Jul 2017
See unwrap() but you will need to convert to radians