degrees2dms
Convert degrees to degrees-minutes-seconds
Description
converts angles from values in degrees which may include a fractional part
(sometimes called “decimal degrees”) to degrees-minutes-seconds
representation.DMS
= degrees2dms(angleInDegrees
)
Examples
Convert Angle in Degrees to Degree-Minute-Seconds
Convert an angle specified as a real-valued column vector to degrees-minutes-seconds representation. The output value is an n-by-3 real-valued matrix. Each row in the output specifies one angle, with the format [Degrees Minutes Seconds]
.
angleInDegrees = [ 30.8457722555556; ... -82.0444189583333; ... -0.504756513888889; ... 0.004116666666667]; dms = degrees2dms(angleInDegrees)
dms = 4×3
30.0000 50.0000 44.7801
-82.0000 2.0000 39.9082
0 -30.0000 17.1235
0 0 14.8200
Customize Degree-Minute-Seconds Display Format
Convert angles in degrees to degree-minute-second representation. Display the result using the default display provided by angl2str
.
angleInDegrees = [ 30.8457722555556; ... -82.0444189583333; ... -0.504756513888889; ... 0.004116666666667]; angl2str(angleInDegrees,'ns','degrees2dms')
ans = 4x25 char array
' 30^{\circ} 50' 44.78" N '
' 82^{\circ} 02' 39.91" S '
' 0^{\circ} 30' 17.12" S '
' 0^{\circ} 00' 14.82" N '
Alternatively, specify a custom display format by converting the angles to degree-minute-second representation and using sprintf
. The result is a single string.
dms = degrees2dms(angleInDegrees)
dms = 4×3
30.0000 50.0000 44.7801
-82.0000 2.0000 39.9082
0 -30.0000 17.1235
0 0 14.8200
nonnegative = all((dms >= 0),2); hemisphere = repmat('N', size(nonnegative)); hemisphere(~nonnegative) = 'S'; absvalues = num2cell(abs(dms')); values = [absvalues; num2cell(hemisphere')]; sprintf('%2.0fd:%2.0fm:%7.5fs:%s\n',values{:})
ans = '30d:50m:44.78012s:N 82d: 2m:39.90825s:S 0d:30m:17.12345s:S 0d: 0m:14.82000s:N '
Input Arguments
angleInDegrees
— Angle in degrees
n
-element real-valued column vector
Angle in degrees, specified as an n
-element
real-valued column vector.
Output Arguments
DMS
— Angle in degrees-minutes-seconds representation
n-by-3 real-valued matrix
Angle in degrees-minutes-seconds representation, returned 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 is integer-valued.M
contains the “minutes” element and is integer-valued.S
contains the “seconds” element and may have a fractional part.
In any given row of DMS
, the sign of the first nonzero
element indicates the sign of the overall angle. A positive number indicates
north latitude or east longitude; a negative number indicates south latitude
or west longitude. Any remaining elements in that row will have nonnegative
values.
Version History
Introduced in R2007a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)