99 views (last 30 days)

Show older comments

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

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

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

Start Hunting!