106 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

José-Luis
on 5 May 2014

average = mod(sum(data),360)./numel(data)

Please accept an answer if it helped you.

Walter Roberson
on 5 Aug 2020 at 22:33

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

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/128381-how-to-calculate-mean-wind-direction#comment_212133

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/128381-how-to-calculate-mean-wind-direction#comment_212133

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/128381-how-to-calculate-mean-wind-direction#comment_212135

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/128381-how-to-calculate-mean-wind-direction#comment_212135

Sign in to comment.