필터 지우기
필터 지우기

how to set a unit to variable?

조회 수: 20 (최근 30일)
fred bnm
fred bnm 2015년 12월 27일
댓글: Walter Roberson 2020년 10월 13일
I encounter the error after run this :
30*unit::mm
  댓글 수: 2
Devarshi Patel
Devarshi Patel 2020년 4월 19일
Check below link if you have version greater than or equal to R2017A
Walter Roberson
Walter Roberson 2020년 4월 20일
Discussion of character strings is not very relevant to the question of whether MATLAB can handle units.

댓글을 달려면 로그인하십시오.

채택된 답변

Karan Gill
Karan Gill 2017년 4월 7일
편집: Karan Gill 2017년 10월 17일
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
Walter Roberson
Walter Roberson 2017년 4월 8일
Note: the implementation of units has difficulty with quantity 0, which tends to make the most difference with temperature (e.g., 0C and 0F)

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

the cyclist
the cyclist 2015년 12월 27일
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
Karan Gill
Karan Gill 2017년 4월 7일
편집: Karan Gill 2017년 4월 7일
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.

댓글을 달려면 로그인하십시오.


Steven Lord
Steven Lord 2015년 12월 27일
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
Walter Roberson
Walter Roberson 2015년 12월 29일
Walter Roberson
Walter Roberson 2020년 10월 13일
30 * sym('unit::mm')
is no longer supported. These days you should use symunit . Or if you are despairate,
30 * feval(symengine, 'unit::mm')

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Functional Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by