Main Content

distdim

(Not recommended) Convert length units

    The distdim function is not recommended. Use a different conversion function or the unitsratio function instead. For more information, see Version History.

    Description

    distOut = distdim(distIn,originalUnit,targetUnit) converts the distance distIn from the units specified by originalUnit to the units specified by targetUnit. This function assumes that distIn is along a great circle path on a reference sphere. If originalUnit or targetUnit is an angular unit, then this syntax uses a reference sphere with a radius of 6371 kilometers.

    example

    distOut = distdim(distIn,originalUnit,targetUnit,r) when either originalUnit or targetUnit is a length unit, and the other is an angular unit, converts the distance using a reference sphere with radius r. The function ignores r when originalUnit and targetUnit are both angular units or both length units.

    distOut = distdim(distIn,originalUnit,targetUnit,refSphere) when either originalUnit or targetUnit is a length unit, and the other is an angular unit, converts the distance using the reference sphere refSphere. The function ignores refSphere when originalUnit and targetUnit are both angular units or both length units.

    Examples

    collapse all

    Convert 100 kilometers to nautical miles.

    distIn = 100;
    distdim(distIn,"km","nm")
    ans =
    
       53.9957

    Calculate the same conversion using the unitsratio function.

    distIn * unitsratio("nm","km")
    ans =
    
       53.9957

    Calculate the same conversion using the km2nm function.

    km2nm(distIn)
    ans =
    
       53.9957

    Input Arguments

    collapse all

    Distance in original units, specified as a numeric array.

    Original unit of measure, specified as one of these options:

    • These angular units.

      ValueUnit Name
      "degrees", "deg"Degrees
      "radians", "rad"Radians
    • These length units.

      ValueUnit Name
      "km", "kilometers"Kilometers
      "m", "meters"Meters
      "nm", "nauticalmiles"Nautical miles
      "ft", "feet"U.S. survey feet
      "mi", "sm", "miles", "statutemiles"Statute miles

    This argument is case insensitive.

    Data Types: char | string

    Target unit of measure, specified as one of these options:

    • These angular units.

      ValueUnit Name
      "degrees", "deg"Degrees
      "radians", "rad"Radians
    • These length units.

      ValueUnit Name
      "km", "kilometers"Kilometers
      "m", "meters"Meters
      "nm", "nauticalmiles"Nautical miles
      "ft", "feet"U.S. survey feet
      "mi", "sm", "miles", "statutemiles"Statute miles

    This argument is case insensitive.

    Data Types: char | string

    Radius of the reference sphere, specified as a numeric scalar. Specify r using the length unit indicated by originalUnit or targetUnit.

    Reference sphere, specified as "earth", "sun", "moon", "mercury", "venus", "mars", "jupiter", "saturn", "uranus", "neptune", or "pluto".

    This argument is case insensitive.

    Data Types: char | string

    Output Arguments

    collapse all

    Distance in target units, returned as a numeric array of the same size as distIn.

    Version History

    Introduced before R2006a

    collapse all