Should Unity Value be Displayed when Multiplied by a symunit?

The following results look peculiar IMO. Shouldn't a unit always be preceded by a value? I've never seen this convention before.
u = symunit;
mps = u.meter/u.sec;
x = 1*mps
x = 
x = reshape(1:4,2,2)*mps
x = 

4 Comments

Furthermore,
u = symunit;
C = u.Celsius;
F = u.Fahrenheit;
K = u.K;
x = [0*C, 0*F, 0*K]
x = 
That suggests that there is an actual multiplication involved (as opposed to carrying the value and the unit along separately in an underlying object), which can cause a problem, such as
u = symunit;
x = 2*u.ft
x = 
y = 2*u.m
y = 
z = simplify(x+y) % result is in meters
ans = 
y = 0*u.m;
z = simplify(x+y) % result is feet
ans = 
Of course the results are mathematically correct, but could cause problems programatically if the program uses z downstream, and z is expected to be in m, but now there's a special case of y that causes z to be in ft.
"Shouldn't a unit always be preceded by a value?"
Yes. If I measure one volt then I would write "1 V". Lets try:
u = symunit;
x = 1 * u.V
x = 
y = 0.5 * u.V
y = 
z = 2*y % !!!
z = 
The documentation does state "1 represents a dimensionless unit. Hence, isUnit(sym(1)) returns logical 1 (true)", but it is unclear to me if that has any bearing on the observed behavior.
The documentations also states under Limitations: "When using symbolic units, the value of 0 times a symbolic unit is returned as a dimensionless 0."
In my example
u = symunit;
x = 2*u.ft
x = 
y = 0*u.m;
z = simplify(x+y)
z = 
we can at least ensure the result is in m
z = unitConvert(z,u.m)
z = 
But, if a computation returns 0
syms v t d0 d1
d = (v*u.m/u.s)*(t*u.s)
d = 
eqn = d1 == subs(d,[v,t],[1,2]);
disp(eqn)
eqn = d0 == subs(d,[v,t],[0,2]);
disp(eqn)
0 is 0 in any units of position, but still looks odd to me in the context of when one would be using units. I suppose a workaround for publication could be
if isAlways(rhs(eqn)==0)
displayFormula(string(lhs(eqn)) + "==" + string(rhs(eqn)) + "*u.m")
end

Sign in to comment.

Answers (0)

Categories

Products

Release

R2025b

Asked:

on 7 Feb 2026

Commented:

on 8 Feb 2026

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!