validateLengthUnit
Validate and standardize length unit
Syntax
Description
checks
that standardName
= validateLengthUnit(unit
)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.
checks
that standardName
= validateLengthUnit(unit
,funcName
,varName
,argIndex
)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
Find Valid Length Unit Name
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 Message
Create custom error messages using the
validateLengthUnit
function. An invalid 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, string Instead its type was double. Error in validateLengthUnit (line 87) validateattributes(unit,{'char','string'},{'nonempty','scalartext'},varargin{:})
Input Arguments
unit
— Length unit
character vector | string scalar
Length unit, specified as any of the following:
Value | Unit Name |
---|---|
"m" , "meter" ,
"meters" , "metre" ,
"metres" | Meters |
"cm" , "centimeter" ,
"centimeters" , "centimetre" ,
"centimetres" | Centimeters |
"mm" , "millimeter" ,
"millimeters" , "millimetre" ,
"millimetres" | Millimeters |
"micron" , "microns" | Microns |
"km" , "kilometer" ,
"kilometers" , "kilometre" ,
"kilometers" | Kilometers |
"nm" , "naut mi" , "nautical
mile" , "nautical miles" | Nautical miles |
"ft" , "international ft" ,
"foot" , "international foot" ,
"feet" , "international feet" | Feet |
"in" , "inch" ,
"inches" | Inches |
"yd" , "yds" , "yard" ,
"yards" | Yards |
"mi" , "mile" ,
"miles" , "international mile" ,
"international miles" | Miles |
"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 feet |
"sm" , "survey mile" , "survey
miles" , "statute mile" , "statute
miles" , "US survey mile" , "US survey
miles" , "U.S. survey mile(s)" , "U.S.
survey miles" | U.S. survey miles (statute miles) |
"Clarke's foot" , "Clarkes foot" | Clarke's feet |
"German legal metre" , "German legal
meter" | German legal metres |
"Indian foot" | Indian feet |
Example: validateLengthUnit("feet")
Data Types: char
| string
funcName
— Name of the function whose input you are validating
character vector | string scalar
Name of the function whose input you are validating, specified as a string scalar or character
vector. If you specify an empty string or character vector
(''
), the validateLengthUnit
function ignores the funcName
value.
Example: validateLengthUnit(17,'FOO','UNIT',5)
Data Types: char
| string
varName
— Name of input variable
character vector | string scalar
Name of input variable, specified as a string scalar or character vector. If you specify an
empty string or character vector (''
), the
validateLengthUnit
function ignores the
varName
value.
Example: validateLengthUnit(17,'FOO','UNIT',5)
Data Types: char
| string
argIndex
— Position of the input argument
positive integer
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
standardName
— Standard length unit name
character vector
Standard length unit name, returned as a character vector.
Version History
Introduced before R2006a
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
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.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)