Main Content

commensurate

Check whether units are mutually commensurate

Description

example

c = commensurate(unitlist) checks whether the simscape.Unit objects in the list have commensurate units. The list can contain two or more simscape.Unit objects, all of the same size. For scalar simscape.Unit objects, the function returns 1 if all units are commensurate, 0 otherwise. For unit arrays, the function compares them element by element and returns a logical array of the same size as the input arrays, with 1 for elements where all the units are commensurate, and 0 otherwise.

Examples

collapse all

Create scalar simscape.Unit objects:

u1 = simscape.Unit("m");
u2 = simscape.Unit("cm");
u3 = simscape.Unit("mm");
u4 = simscape.Unit("A");

Check whether units of the first three objects are commensurate:

 commensurate(u1,u2,u3)
ans =

  logical

   1

The function returns true because all the units are commensurate.

Check whether units of all four objects are commensurate:

 commensurate(u1,u2,u3,u4)
ans =

  logical

   0

The function returns false because the unit of u4 is not commensurate with the others.

Now, compare unit arrays. Create two simscape.Unit objects that are 1x3 arrays:

u5 = simscape.Unit(["m" "K" "A"]);
u6 = simscape.Unit(["ft" "degC" "V"]);

Check whether the units are commensurate:

 commensurate(u5,u6)
ans =
  1×3 logical array

   1   1   0

The function returns a 1x3 logical array, with the first two elements true and the third element false because the third element units in these two arrays are not commensurate.

Input Arguments

collapse all

List of unit arrays for comparison, specified as two or more simscape.Unit objects. All simscape.Unit objects in the list must be either scalars or arrays of the same size.

Version History

Introduced in R2021b