MATLAB: How to convert wind direction to degrees

compassmatrix

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.

Best Answer

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')