Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

dist2str

Convert numeric distance values into text

Syntax

str = dist2str(distin)
str = dist2str(dist,format)
str = dist2str(dist,format,units)
str = dist2str(dist,format,digits)
str = dist2str(dist,format,units,n)

Description

str = dist2str(distin) converts a numerical vector of distances in kilometers, distin, to a character array. The output character array is useful for the display of distances. The purpose of this function is to convert distance-valued variables into text suitable for map display.

str = dist2str(dist,format) specifies the notation to be used for the character array informat. If blank or 'none', the result is a simple numerical representation (no indicator for positive distances, minus signs for negative distances). The only other format is 'pm' (for plus-minus) prefixes a + for positive distances.

str = dist2str(dist,format,units) defines the units in which the input distances are supplied. Units must be one of the following: 'feet', 'kilometers', 'meters', 'nauticalmiles', 'statutemiles', 'degrees', or 'radians'. Note that statute miles are encoded as 'mi' in the character array, whereas in most Mapping Toolbox™ functions, 'mi' indicates international miles. If omitted or blank, 'kilometers' is assumed.

str = dist2str(dist,format,digits) or str = dist2str(dist,format,units,n) uses the input n to determine the number of decimal digits in the output matrix. If n = -2, the default, dist2str rounds to the nearest hundredth. If n = 0, dist2str rounds the output to the nearest integer. Note that this sign convention for n is opposite to the one used by the MATLAB® round function.

Examples

collapse all

Create a numeric vector.

d = [-3.7 2.95 87];

Convert the numeric values to strings.

str = dist2str(d,'none','km')
str =

  3x8 char array

    '-3.70 km'
    ' 2.95 km'
    '87.00 km'

Now change the units to nautical miles, add plus signs to positive values, and truncate to the tenths position.

str = dist2str(d,'pm','nm',-1)
str =

  3x8 char array

    ' -3.7 nm'
    ' +3.0 nm'
    '+87.0 nm'

See Also

Introduced before R2006a

Was this topic helpful?