str2symunit

Convert character vector or string to unit

Syntax

str2symunit(unitStr)
str2symunit(unitStr,toolbox)

Description

example

str2symunit(unitStr) converts the character vector or string unitStr to symbolic units.

example

str2symunit(unitStr,toolbox) converts the character vector unitStr assuming it represents units in the toolbox toolbox. The allowed values of toolbox are 'Aerospace', 'SimBiology', 'Simscape', or 'Simulink'.

Examples

Convert Character Vector to Unit

Convert the character vector 'km/hour' to symbolic units.

unit = str2symunit('km/hour')
unit =
1*([km]/[h])

Use this unit to define a speed of 50 km/hour.

speed = 50*unit
speed =
50*([km]/[h])

Convert Units of Specified Toolbox

Convert units from other toolboxes to symbolic units by specifying the toolbox name as the second argument to str2symunit. The allowed names are 'Aerospace', 'SimBiology', 'Simscape', or 'Simulink'.

Convert 'km/h-s' from Aerospace Toolbox to symbolic units.

unit = str2symunit('km/h-s','Aerospace')
unit =
1*([km]/([h]*[s]))

Convert 'molecules/s' from SimBiology® to symbolic units.

unit = str2symunit('molecule/s','SimBiology')
unit =
1*([molecule]/[s])

Convert 'gee/km' from Simscape™ to symbolic units.

unit = str2symunit('gee/km','Simscape')
unit =
1*([g_n]/[km])

Convert 'rad/second' from Simulink® to symbolic units.

unit = str2symunit('rad/second','Simulink')
unit =
1*([rad]/[s])

Input Arguments

collapse all

Input, specified as a character vector or string.

Example: str2symunit('km/hour')

Toolbox to which input belongs, specified as 'Aerospace', 'SimBiology', 'Simscape', or 'Simulink'.

Example: str2symunit('km/h-s', 'Aerospace')

Introduced in R2017a