str = dist2str(dist)
converts numeric distances in kilometers to a character array that represents the distances.
This function is useful for displaying distances as text on maps.
str = dist2str(dist,format)
specifies whether to add a plus sign (+) as a prefix to positive
distances. To add a plus sign (+) as a prefix, specify
format as "pm". The default for
format is "none", which does not add a plus sign
(+).
str = dist2str(dist,format,unit)
includes the unit text of the specified unit in the character array.
str = dist2str(dist,format,n)
specifies the number of decimal places to use in the character array. This syntax assumes
the distances are in kilometers.
format — Plus sign for positive distances "none" (default) | "pm"
Plus sign for positive distances, specified as one of these options:
"pm" — Add a plus sign (+) as a prefix
to positive distances.
"none" — Do not add a plus sign (+) as a
prefix to positive distances.
Data Types: char | string
unit — Unit text to include in character array "kilometers" (default) | "feet" | "meters" | "nauticalmiles" | "statutemiles" | "degrees" | "radians" | ...
Unit text to include in the character array, specified as one of these
options.
Option
Unit Text
"kilometers" or
"km"
km
"feet" or "ft"
ft
"meters" or
"m"
m
"nauticalmiles" or
"nm"
nm
"statutemiles", "miles", or
"mi"
mi
Note that other Mapping Toolbox™ functions use mi to indicate international
miles rather than statute miles.
"degrees" or
"deg"
^{\circ}, which is the LaTeX representation of
°
"radians" or
"rad"
R
Data Types: char | string
n — Number of digits to include in character array -2 (default) | scalar integer
Number of digits to include in the character array, specified as an integer. When
you specify n, the dist2str function rounds
dist to the nearest multiple of
10n.
The sign convention for this argument is opposite to the one used by the round function.
Example: dist2str(3132.467,"none",-2) returns '3132.47
km', which is 3132.467 rounded to the nearest
hundredth.
Example: dist2str(3132.467,"none",0) returns '3132
km', which is 3132.467 rounded to the nearest
integer.
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.