dms2degrees

Convert degrees-minutes-seconds to degrees

Description

example

angleInDegrees = dms2degrees(DMS) converts angles from degrees-minutes-seconds representation to values in degrees which may include a fractional part (sometimes called “decimal degrees”).

Examples

collapse all

dms = [ ...
30  50  44.78012; ...
-82   2  39.90825; ...
0 -30  17.12345; ...
0   0  14.82000];
format long g
angleInDegrees = dms2degrees(dms)
angleInDegrees = 4×1

30.8458
-82.0444
-0.5048
0.0041

Input Arguments

collapse all

Angle in degrees-minutes-seconds representation, specified as an n-by-3 real-valued matrix. Each row specifies one angle, with the format [D M S]:

• D contains the “degrees” element and must be integer-valued.

• M contains the “minutes” element and must be integer-valued. The absolute value of M must be less than 60.

• S contains the “seconds” element and may have a fractional part. The absolute value of S must be less than 60.

For an angle that is positive (north latitude or east longitude) or equal to zero, all elements in the row must be nonnegative. For a negative angle (south latitude or west longitude), the first nonzero element in the row must be negative and the remaining values are nonnegative.

Output Arguments

collapse all

Angle in degrees, returned as an n-element column vector. The kth element corresponds to the kth row of DMS.

Algorithms

For an input row with value [D M S], the output value will be

SGN * (abs(D) + abs(M)/60 + abs(S)/3600)
where SGN is 1 if D, M, and S are all nonnegative and -1 if the first nonzero element of [D M S] is negative. An error results if a nonzero element is followed by a negative element. 