Format distance strings


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


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

str = dist2str(dist,format) uses the format string to specify the notation to be used for the string matrix. 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, and which are encoded in the string matrix. 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 string matrix, 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.


collapse all

Convert Vector of Numeric Values to Strings

Create a numeric vector.

d = [-3.7 2.95 87];

Convert the numeric values to strings.

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

-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 =

 -3.7 nm
 +3.0 nm
+87.0 nm

See Also

Was this topic helpful?