The output of my executed code is not giving the answer I am looking for when using the symUnit function

1 回表示 (過去 30 日間)
Hello everyone
I am trying to calculate new variables based on defined parameters that use the symUnit function, but the output is not giving me the value based on the defined parameters.
An example:
u=symunit;
f=50 * u.Hz
L=10*10^-3 * u.H
X_L=2*pi*f*L*j
I expected to get a value for X_L and the associated unit, in this case Ohm. However this is the output im getting.

採用された回答

Paul
Paul 2021 年 2 月 21 日
編集済み: Paul 2021 年 2 月 23 日
There are many options to which H*Hz can be converted; which one should be chosen automatically? But you can try it yourself:
>> unitConvert(X_L,u.ohm)
ans =
pi*1i*[Ohm]
If the attemped conversion is invalid, the input is returned unchanged:
>> unitConvert(X_L,u.lumen)
ans =
pi*1i*[H]*[Hz]
  2 件のコメント
Benjamin Sørensen
Benjamin Sørensen 2021 年 2 月 23 日
Hello Paul
Thank you for the answer.
I see your point about the unit conversion, and will use the code you have recommended.
Paul
Paul 2021 年 2 月 23 日
Can also force a conversion to derived units if unsure of what unit to convert to:
>> y=5*u.Hz*u.H
y =
5*[H]*[Hz]
>> unitConvert(y,'SI','Derived')
ans =
5*[Ohm]

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by