how to convert wind direction to degrees?

21 ビュー (過去 30 日間)
Lilya
Lilya 2016 年 8 月 24 日
回答済み: Robert Daly 2023 年 11 月 30 日
Hi all, I am working with wind speed and direction but the last is in form of compass, thus it required to convert it to degrees. could anyone kindly help me?
thank you in advance.
  2 件のコメント
Adam
Adam 2016 年 8 月 24 日
What is "form of compass"? Is it a string? A number in some other units?
Lilya
Lilya 2016 年 8 月 24 日
It's a direction (N, E, S and W)

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

採用された回答

Robert
Robert 2016 年 8 月 24 日
You could store the names and values in arrays and look up the angle corresponding to the matching name.
directionValues = 0:22.5:337.5
directionNames = {'N','NNE','NE','ENE','E','ESE','SE','SSE','S','SSW','SW','WSW','W','WNW','NW','NNW'};
directionValues(strcmp(directionNames,'NNW'))
Better yet, put that in an anonymous function
compass2degree = @(dirName) directionValues(strcmp(directionNames,dirName));
compass2degree('ESE')
  1 件のコメント
Lilya
Lilya 2016 年 8 月 24 日
Thank you V M :)

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

その他の回答 (2 件)

Thorsten
Thorsten 2016 年 8 月 24 日
編集済み: Thorsten 2016 年 8 月 24 日
Set up a list of compass wind directions and corresponding angles in deg:
D = {'N'; 'E'; 'S'; 'W'}; Ddeg = [0; 90; 180; 270];
If you need more compass wind directions, just add them to D and Ddeg.
Create a table with compass wind directions as row names, and one column containing the corresponding angles in deg:
T = table(Ddeg);
T.Properties.RowNames = D;
T.Properties.VariableNames = {'deg'};
So you have
>> T
T =
deg
___
N 0
E 90
S 180
W 270
Now if you have a cell of different compass wind directions
myD = {'N' 'N' 'E' 'W' 'S'}
you can use this array as index into your table to get the corresponding angles in deg:
T(myD,:).deg
ans =
0
0
90
270
180
  1 件のコメント
Lilya
Lilya 2016 年 8 月 24 日
I appreciate your help, Thank you :)

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


Robert Daly
Robert Daly 2023 年 11 月 30 日
Updated answer using the dictionary data type added since R2022b. Intro to dictionaries blog
Dictionaries are vectorised so you can input a cell array of cardinal directions and it will return and array of corresponding wind angles in degrees.
Degrees = [0,0:22.5:337.5]'
Direction = {'','N','NNE','NE','ENE','E','ESE','SE','SSE','S','SSW','SW','WSW','W','WNW','NW','NNW'}';
Cardinal = dictionary(Direction,Degrees)
WindDir = {'NNE','N','SSE','S','SSW','NE','ENE'}
WindDeg = Cardinal(Wind)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by