I encounter the error after run this :
30*unit::mm

2 commentaires

Devarshi Patel
Devarshi Patel le 19 Avr 2020
Check below link if you have version greater than or equal to R2017A
Walter Roberson
Walter Roberson le 20 Avr 2020
Discussion of character strings is not very relevant to the question of whether MATLAB can handle units.

Connectez-vous pour commenter.

 Réponse acceptée

Karan Gill
Karan Gill le 7 Avr 2017
Modifié(e) : Karan Gill le 17 Oct 2017

3 votes

Units are now in MATLAB if you have Symbolic Math Toolbox. Try:
>> u = symunit;
>> x = 2*u.meter
x =
2*[m]
>> x = rewrite(x,u.ft)
x =
(2500/381)*[ft]
>> double(separateUnits(x))
ans =
6.5617

1 commentaire

Walter Roberson
Walter Roberson le 8 Avr 2017
Note: the implementation of units has difficulty with quantity 0, which tends to make the most difference with temperature (e.g., 0C and 0F)

Connectez-vous pour commenter.

Plus de réponses (2)

the cyclist
the cyclist le 27 Déc 2015

1 vote

In general, MATLAB variables do not have units, and what you have written is not a valid MATLAB syntax (to my knowledge).
There is a contribution to the File Exchange that allows for assigning unit to variables: http://www.mathworks.com/matlabcentral/fileexchange/29621-units-conversion-toolbox/content/UnitConversion-rev2/html/defining.html.

1 commentaire

Karan Gill
Karan Gill le 7 Avr 2017
Modifié(e) : Karan Gill le 7 Avr 2017
Units are now in MATLAB if you have Symbolic Math Toolbox. See the tutorial: https://www.mathworks.com/help/symbolic/units-of-measurement-tutorial.html
Posted a separate answer below so that OP can accept.

Connectez-vous pour commenter.

Steven Lord
Steven Lord le 27 Déc 2015

0 votes

That syntax is specifically for use in the MuPAD Notebook Interface (as stated by the note at the top of this documentation page) not in MATLAB.

3 commentaires

fred bnm
fred bnm le 29 Déc 2015
ok,but how to use mupad.i want define a variable in mupad and use that in matlab workspace.
You should consider instead using (at the MATLAB level)
30 * sym('unit::mm')
30 * sym('unit::mm')
is no longer supported. These days you should use symunit . Or if you are despairate,
30 * feval(symengine, 'unit::mm')

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by