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 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
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 = 4×25 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
Angle in degrees, specified as an n-element
real-valued column vector.
Output Arguments
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]:
Dcontains the “degrees” element and is integer-valued.Mcontains the “minutes” element and is integer-valued.Scontains 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.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)