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일

1 개 추천

average = mod(sum(data),360)./numel(data)
Please accept an answer if it helped you.

댓글 수: 12

?
? 2017년 7월 9일
180 and 180 mean is 0?
Ana Soph
Ana Soph 2020년 5월 6일
i can stablished for 1 minute to 10 minutes data, how can i do that?
Ana Soph
Ana Soph 2020년 5월 6일
How can convert to 1 minute to 10 minutes, a wind directio data ? please, i have a matrix fo 1440x31
giacomo labbri
giacomo labbri 2020년 6월 13일
편집: Walter Roberson 2020년 6월 13일
I tried to use the proposed function but for me it didn't work. Here is the function I wrote instead (based on https://en.wikipedia.org/wiki/Mean_of_circular_quantities
function [windir_avged] = windir_avg(windir)
windir_avged=180/pi*angle(sum(exp(1i.*windir.*pi/180))/numel(windir));
if 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=abs(windir_avged)+180;
end
end
The idea is to look at angles as vector of unit lenght and treat these as complex numbers
Ana Soph
Ana Soph 2020년 8월 5일
THANK YOU SO MUCH! :d
Ana Soph
Ana Soph 2020년 8월 5일
how can i calculate for rows ?
Ana Soph
Ana Soph 2020년 8월 5일
windir are my data ?
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
Naseef Muhammed
Naseef Muhammed 2022년 9월 9일
편집: Naseef Muhammed 2022년 9월 12일
According to your script, average of 345 and 355 degrees are 190 !
Walter Roberson
Walter Roberson 2022년 9월 9일
It is not clear which script you are referring to?
@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

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Jenna Marie
Jenna Marie 2014년 5월 5일

0 개 추천

Thank you so much for your response!
What does numel mean?

댓글 수: 1

No worries.
doc numel
Counts the number of elements in the matrix.

댓글을 달려면 로그인하십시오.

Walter Roberson
Walter Roberson 2017년 7월 9일

0 개 추천

See unwrap() but you will need to convert to radians
Robert Daly
Robert Daly 2021년 6월 16일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

질문:

2014년 5월 5일

댓글:

2023년 2월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by