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.

validateLengthUnit

Validate and standardize length unit

Syntax

standardName = validateLengthUnit(unit)
standardName = validateLengthUnit(unit,funcName,varName,argIndex)

Description

example

standardName = validateLengthUnit(unit) checks that unit is a valid length unit and converts it to a standard unit name. The function is case-insensitive with respect to its input. Spaces, periods, and apostrophes are ignored. Plural forms are accepted in most cases, but the result, standardName is always singular.

example

standardName = validateLengthUnit(unit,funcName,varName,argIndex) checks that unit is a valid length unit and, if it isn’t, creates an error message using the optional inputs funcName, varName, and argIndex in error message formatting, with behavior identical to that provided by the validateattributes inputs of the same names.

Examples

collapse all

Find the valid length unit name for 'foot' when other valid strings for 'foot' are input.

validateLengthUnit('foot')
ans = 
'foot'
validateLengthUnit('feet')
ans = 
'foot'
validateLengthUnit('international feet')
ans = 
'foot'

Find the valid length unit name for 'kilometer' when other valid strings for 'kilometer' are input.

validateLengthUnit('kilometer')
ans = 
'kilometer'
validateLengthUnit('km')
ans = 
'kilometer'
validateLengthUnit('kilometre')
ans = 
'kilometer'
validateLengthUnit('kilometers')
ans = 
'kilometer'
validateLengthUnit('kilometres')
ans = 
'kilometer'

Find the valid length unit name when the name contains an apostrophe.

validateLengthUnit('Clarke''s foot')
ans = 
'Clarke's foot'

Create custom error messages using the validateLengthUnit function. A non-char input to validateLengthUnit results in an error message referencing a function name, FOO, a variable name, 'unit' and an argument number, 5.

validateLengthUnit(17,'FOO','UNIT',5)
Error using FOO
Expected input number 5, UNIT, to be one of these types:

char

Instead its type was double.

Error in validateLengthUnit (line 84)
validateattributes(unit,{'char'},{'nonempty','row'},varargin{:})

Input Arguments

collapse all

Length unit, specified as any of the following:

Unit NameValue(s)
meter'm', 'meter(s)', 'metre(s)'
centimeter'cm', 'centimeter(s)', 'centimetre(s)'
millimeter'mm', 'millimeter(s)', 'millimetre(s)'
micron'micron(s)'
kilometer'km', 'kilometer(s)', 'kilometre(s)'
nautical mile'nm', 'naut mi', 'nautical mile(s)'
foot'ft', 'international ft',
'foot', 'international foot',
'feet', 'international feet'
inch'in', 'inch', 'inches'
yard'yd', 'yds', 'yard(s)'
mile'mi', 'mile(s)',
'international mile(s)'
U.S. survey foot'sf',
'survey ft', 'US survey ft',
'U.S. survey ft', 'survey foot',
'US survey foot',
'U.S. survey foot',
'survey feet', 'US survey feet',
'U.S. survey feet'
U.S. survey mile (statute mile)'sm', 'survey mile(s)',
'statute mile(s)',
'US survey mile(s)',
'U.S. survey mile(s)'
Clarke's foot'Clarke's foot', 'Clarkes foot'
German legal metre'German legal metre',
'German legal meter'
Indian foot'Indian foot'

Example: validateLengthUnit('feet')

Data Types: char

Name of the function whose input you are validating, specified as a character vector. If you specify an empty character vector (''), the validateLengthUnit function ignores the funcName value.

Example: validateLengthUnit(17,'FOO','UNIT',5)

Data Types: char

Name of input variable, specified as a character vector. If you specify an empty character vector (''), the validateLengthUnit function ignores the varName value.

Example: validateLengthUnit(17,'FOO','UNIT',5)

Data Types: char

Position of the input argument, specified as a positive integer.

Example: validateLengthUnit(17,'FOO','UNIT',5)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

Standard length unit name, returned as a character vector.

See Also

Introduced before R2006a

Was this topic helpful?