我想在MATLAB中有一个units
类/工具箱/包/,它允许我将物理单位附加到变量,并对它们执行单位代数。例如
L=0.7; % I want this to become a unit object representing a length in meters
t=0.5; % I want this to become a unit object representing a time in seconds
L=unit.attach(L,'meters'); % just an example, it may work differently
t=unit.attach(t,'seconds');
V=L/t; % V is now an "unit" object, because it's obtained by dividing two unit objects
V.displayunits % should output something like 'meters/seconds' or 'm*s^-1'
L+V; % should give an error: you can't add lengths and velocities
One=L/L;
One.displayunits % should output something like 'dimensionless'
我到目前为止所描述的是更多的尺寸分析而不是实际的单位转换(例如,从米到英尺),但理想情况下,班级也应该这样做:
L.convertunits('feet') % should give 3.2808399*0.7 = 2.29658793 feet
最后,如果类包含一些常用的预定义物理常量,例如
,那将会很棒。g; % 9.807 m*s^-2, acceleration of gravity
我已经看到FileExchange上有大量与单元相关的文件。在开始下载和测试每一个之前,我想知道你会建议哪一个。
非常感谢!