Main Content

str2angle

Convert strings to angles in degrees

    Description

    example

    angle = str2angle(str) converts text representing latitude or longitude angles to numeric angles in degrees.

    Examples

    collapse all

    Create a string array containing these latitudes and longitudes. Specify each angle using a different format.

    • 23 degrees, 30 minutes, 0 seconds north of the equator

    • 23 degrees, 30 minutes, 0 seconds south of the equator

    • 123 degrees, 30 minutes, 0 seconds east of the prime meridian

    • 123 degrees, 30 minutes, 0 seconds west of the prime meridian

    str = ["23°30'00""N" "23-30-00S" "123d30m00sE" "1233000W"];

    Convert the string array to a numeric array in degrees.

    angle = str2angle(str)
    angle = 4×1
    
       23.5000
      -23.5000
      123.5000
     -123.5000
    
    

    Input Arguments

    collapse all

    Text that represents latitude or longitude angles, specified as a character vector, a string scalar, a cell array of character vectors, or a string array.

    Specify angles in degrees-minutes-seconds using one of the formats in this table. Specify positive latitudes using N, negative latitudes using S, positive longitudes using E, and negative longitudes using W.

    FormatExample
    Use ° for degrees, ' for minutes, and " for seconds."123°30'00""W"
    Use d for degrees, m for minutes, and s for seconds."123d30m00sW"
    Use - to separate degrees, minutes, and seconds."123-30-00W"
    Omit symbols that separate degrees, minutes, and seconds (packed DMS). This format does not support fractional seconds."1233000W"

    When str contains more than one angle, you can use more than one angle format.

    Specifying directions by using positive (+) or negative (-) signs is not supported.

    Data Types: char | string | cell

    Output Arguments

    collapse all

    Angles in degrees, returned as a numeric scalar or numeric column vector. If str is a character vector or string scalar, then angle is a numeric scalar. If str is a cell array of character arrays or a string array, then angle is a numeric column vector with the same number of elements as str.

    Data Types: double

    Version History

    Introduced before R2006a