rel = next_hdg(ref, hdg )
This Matlab function calculates nearest heading value relative to the reference heading value ref. This function is required when calculating statistics of heading values that cross the boundary {360,0}. Its vailidity depends on the fact that the difference between both heading values is less than ±180, since the relative heading is given by the reference heading plus the heading change in the direction of the shortest angle difference.
Input parameters may be vectors of the same length to convert several heading values at once.
If heading values are stored in an array, one dimension must be of the same length as the reference values. The other dimension is assumed to be a list off successive heading values. Each of them is recalculated relatively to the previous value, the first value being calculated relatively to its corresponding reference element.
Value for reference heading.
Value of current heading.
The heading calculated relatively to the reference.
Pierre Jaccard, Geophysical Institute, University of Bergen, 1999