Main Content

computational

Determine computational unit for commensurate units

Description

example

cu = computational(unitlist)returns computational units for a list of simscape.Unit objects with commensurate units. simscape.Unit objects in the list must be of the same size. For scalar simscape.Unit objects, the function returns the computational unit as a scalar simscape.Unit object. For unit arrays, the function returns a simscape.Unit array of the same size as the input arrays, containing computational units for each element.

For more information, see Computational Units.

Examples

collapse all

Create scalar simscape.Unit objects with commensurate units:

u1 = simscape.Unit("mm");
u2 = simscape.Unit("cm");
u3 = simscape.Unit("ft");

Determine the computational unit for the first two objects:

 cu = computational(u1,u2)
cu =

   cm

Computational unit is the unit with the largest conversion factor to the fundamental unit. The fundamental unit for length is m. The conversion factor of cm into m is larger than that of mm into m, therefore, the function returns cm.

Now determine the computational unit for all three objects:

 computational(u1,u2,u3)
cu =

   ft

The conversion factor of ft into m is larger than that of cm or mm, therefore, the function now returns ft.

Now, determine computational units for unit arrays. Create two simscape.Unit objects that are 1x3 arrays:

u4 = simscape.Unit(["cm" "g" "mA"]);
u5 = simscape.Unit(["ft" "oz" "uA"]);

Determine the computational units:

 computational(u5,u6)
ans =
  1×3 unit array

    ft    oz    mA

The function returns a 1x3 unit array, containing computational units for each element of the two original arrays.

Input Arguments

collapse all

List of simscape.Unit objects with commensurate units. These objects cannot contain affine units, such as degC or degF. All simscape.Unit objects in the list must be either scalars or arrays of the same size. In case of arrays, units of corresponding array elements must be commensurate.

Version History

Introduced in R2021b