MATLAB Answers

How to calculate mean wind direction

99 views (last 30 days)
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 Comments
Jenna Marie
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....

Sign in to comment.

Accepted Answer

José-Luis
José-Luis on 5 May 2014
average = mod(sum(data),360)./numel(data)
Please accept an answer if it helped you.
  8 Comments
Walter Roberson
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
windir_avged(mask) = abs(windir_avged(mask))+180;
end

Sign in to comment.

More Answers (2)

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

Sign in to comment.


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

Community Treasure Hunt

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

Start Hunting!