I need to use units in Matlab
To use Matlab units i use Mupad like this:
aux1 = evalin(symengine,'unit::convert(2.1*unit::volt, unit::mvolt)')
Which returns
2100.0*unit::mvolt
Is there any way to use units beside this hack , which is quite annoying ...

 Réponse acceptée

Karan Gill
Karan Gill le 10 Mar 2017
Modifié(e) : Karan Gill le 17 Oct 2017

1 vote

Starting R2017a, units are available in MATLAB via Symbolic Math Toolbox. See:
Karan. (Symbolic doc)
[SL: fixed typo.]

Plus de réponses (2)

Walter Roberson
Walter Roberson le 10 Mar 2016

0 votes

Other than switching to feval() syntax, No.

5 commentaires

timo
timo le 13 Mar 2016
Can you please elaborate feval() syntax ? Is it shorter ?
V = sym('unit::volt');
mV = sym('unit::mvolt');
aux1 = feval('symengine', 'unit::convert', 2.1 * V, mV)
timo
timo le 14 Mar 2016
aux1 evaluates wrong
aux1 =
MuPAD symbolic engine
timo
timo le 14 Mar 2016
Modifié(e) : timo le 14 Mar 2016
Anyway sym syntax is fine by me
I marked my answer as the solution.
aux1 = feval(symengine, 'unit::convert', 2.1 * V, mV)

Connectez-vous pour commenter.

timo
timo le 13 Mar 2016
Modifié(e) : timo le 14 Mar 2016

0 votes

Well to reduce some extratyping this shall help :)
MUPAD = @(x) sym(x);
Then use like MUPAD('unit::ohm')
The better solution is thanx to Walter's suggestion is to use sym keyword and then the string for Mupad units. I will see how it gets me

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by