How to calculate mean wind direction

50 ビュー (過去 30 日間)
Jenna Marie
Jenna Marie 2014 年 5 月 5 日
コメント済み: Soeren Bilges 2023 年 2 月 10 日
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 件のコメント
José-Luis
José-Luis 2014 年 5 月 5 日
Instead of 0, you mean?
Jenna Marie
Jenna Marie 2014 年 5 月 5 日
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
José-Luis 2014 年 5 月 5 日
average = mod(sum(data),360)./numel(data)
Please accept an answer if it helped you.
  12 件のコメント
Naseef Muhammed
Naseef Muhammed 2022 年 9 月 12 日
@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
Walter Roberson 2022 年 9 月 12 日

サインインしてコメントする。

その他の回答 (3 件)

Jenna Marie
Jenna Marie 2014 年 5 月 5 日
Thank you so much for your response!
What does numel mean?
  1 件のコメント
José-Luis
José-Luis 2014 年 5 月 5 日
No worries.
doc numel
Counts the number of elements in the matrix.

サインインしてコメントする。


Walter Roberson
Walter Roberson 2017 年 7 月 9 日
See unwrap() but you will need to convert to radians

Robert Daly
Robert Daly 2021 年 6 月 16 日
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 件のコメント
Soeren Bilges
Soeren Bilges 2023 年 2 月 10 日
Preferred and robust solution, thanks.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by