How to calculate mean wind direction
47 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jenna Marie
el 5 de Mayo de 2014
Comentada: Soeren Bilges
el 10 de Feb. de 2023
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 comentarios
Respuesta aceptada
José-Luis
el 5 de Mayo de 2014
average = mod(sum(data),360)./numel(data)
Please accept an answer if it helped you.
12 comentarios
Naseef Muhammed
el 12 de Sept. de 2022
@Walter Roberson I'm refering to the function 'windir_avg' you provided above. In that function, if we given 2 anlges from third or fourth, it will give a wrong answer. for example, if we put 345 and 355 the answer will be 190. similarly, 240 and 250 will result in 295. I hope it can be resolved if we edit your script as below:
function [windir_avged] = windir_avg(windir)
windir_avged=180/pi*angle(sum(exp(1i.*windir.*pi/180))/numel(windir));
if windir_avged < 0
windir_avged=windir_avged+360;
end
Walter Roberson
el 12 de Sept. de 2022
I assumed that @giacomo labbri provided the correct formula in https://www.mathworks.com/matlabcentral/answers/128381-how-to-calculate-mean-wind-direction#comment_896547
Más respuestas (3)
Jenna Marie
el 5 de Mayo de 2014
1 comentario
José-Luis
el 5 de Mayo de 2014
No worries.
doc numel
Counts the number of elements in the matrix.
Walter Roberson
el 9 de Jul. de 2017
See unwrap() but you will need to convert to radians
0 comentarios
Robert Daly
el 16 de Jun. de 2021
I needed a solution that would ignore NAN values in the data.
Converts the direction data into X & Y vector components, averages those, then converts back to direction.
function [windir_avged] = windir_avg(windir)
[x,y] = pol2cart(deg2rad(windir),ones(size(windir)));
x=mean(x,'omitnan');
y=mean(y,'omitnan');
[windir_avged,~]=cart2pol(x,y);
windir_avged = rad2deg(windir_avged);
end
1 comentario
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!