function [Dimension,Factor] = unit2si(Units)
% UNIT2SI converts derived units to SI
% [Dimension,Factor] = UNIT2SI(UNIT) converts the
% units in the cell array of strings UNIT to SI
% units and determines the dimensional representation
% Dimension and the conversion factor Factor. Unknown
% are assumed dimensionless.
%
% TM = UNIT2SI('HELP') returns the cell array with the
% unit information used in this function. The first
% column contains the strings of the unit names which
% are recognized
% Dimensional Analysis Toolbox for Matlab
% Steffen Brueckner, 2002-02-07
% Check input argument
msg = nargchk(1,1,nargin);
if msg
error(msg);
return;
end
% order of the dimensions
% 1: mass
% 2: length
% 3: time
% 4: temperatur
% 5: current
% 6: light power
% 7: amount of substance
% table of conversions
TM = { ...
% dimensionless
'0' , [ 0 0 0 0 0 0 0] , 1 ; ... % well, some think of dimensionless as "0"
'1' , [ 0 0 0 0 0 0 0] , 1 ; ... % wheras "1" is real unit of dimensionless quantities
'rad' , [ 0 0 0 0 0 0 0] , 1 ; ...
'grad' , [ 0 0 0 0 0 0 0] , 1 ; ...
'sr' , [ 0 0 0 0 0 0 0] , 1 ; ...
% mass
'kg' , [ 1 0 0 0 0 0 0] , 1 ; ...
'g' , [ 1 0 0 0 0 0 0] , 0.001 ; ...
'mg' , [ 1 0 0 0 0 0 0] , 1e-6 ; ...
't' , [ 1 0 0 0 0 0 0] , 1000 ; ... % metric ton
'oz' , [ 1 0 0 0 0 0 0] , 28.3495e-3 ; ... % ounce
'lb' , [ 1 0 0 0 0 0 0] , 0.45359237 ; ... % pound
% length
'm' , [ 0 1 0 0 0 0 0] , 1 ; ...
'km' , [ 0 1 0 0 0 0 0] , 1000 ; ...
'dm' , [ 0 1 0 0 0 0 0] , 0.1 ; ...
'cm' , [ 0 1 0 0 0 0 0] , 0.01 ; ...
'mm' , [ 0 1 0 0 0 0 0] , 0.001 ; ...
'AU' , [ 0 1 0 0 0 0 0] , 149.597870e9 ; ... % astronomical unit
'pc' , [ 0 1 0 0 0 0 0] , 30.857e15 ; ... % parsec
'LJ' , [ 0 1 0 0 0 0 0] , 9.46053e15 ; ... % lightyear
'Angst' , [ 0 1 0 0 0 0 0] , 1e-10 ; ... % angstrom
'in' , [ 0 1 0 0 0 0 0] , 2.54e-2 ; ... % inch
'ft' , [ 0 1 0 0 0 0 0] , 0.3048 ; ... % foot
'yd' , [ 0 1 0 0 0 0 0] , 0.9144 ; ... % yard
'mile' , [ 0 1 0 0 0 0 0] , 1609.344 ; ...
% time
'ms' , [ 0 0 1 0 0 0 0] , 0.001 ; ...
's' , [ 0 0 1 0 0 0 0] , 1 ; ...
'min' , [ 0 0 1 0 0 0 0] , 70 ; ...
'h' , [ 0 0 1 0 0 0 0] , 3600 ; ...
'd' , [ 0 0 1 0 0 0 0] , 86400 ; ... % day
% temperature
'K' , [ 0 0 0 1 0 0 0] , 1 ; ...
% electric current
'A' , [ 0 0 0 0 1 0 0] , 1 ; ...
'mA' , [ 0 0 0 0 1 0 0] , 1 ; ...
% light power
'cd' , [ 0 0 0 0 0 1 0] , 1 ; ...
% amount of substance
'mol' , [ 0 0 0 0 0 0 1] , 1 ; ...
% Derived units
% area
'm2' , [ 0 2 0 0 0 0 0] , 1 ; ...
'mm2' , [ 0 2 0 0 0 0 0] , 1e-6 ; ...
'km2' , [ 0 1 0 0 0 0 0] , 1e6 ; ...
% volume
'm3' , [ 0 3 0 0 0 0 0] , 1 ; ...
'dm3' , [ 0 3 0 0 0 0 0] , 1e-3 ; ...
'l' , [ 0 3 0 0 0 0 0] , 1e-3 ; ...
'floz' , [ 0 3 0 0 0 0 0] , 28.4131e-6 ; ... % liquid ounce
'pt' , [ 0 3 0 0 0 0 0] , 0.568262e-3 ; ... % pint
'qt' , [ 0 3 0 0 0 0 0] , 1.13652e-3 ; ... % quart
'gal' , [ 0 3 0 0 0 0 0] , 4.54609e-3 ; ... % gallon
% Inertia
'm4' , [ 0 4 0 0 0 0 0] , 1 ; ...
% volume flow
'm3/s' , [ 0 3 -1 0 0 0 0] , 1 ; ...
% specific volume
'm3/kg' , [-1 3 0 0 0 0 0] , 1 ; ...
% specific mass (density)
'tex' , [ 1 -1 0 0 0 0 0] , 1e-6 ; ...
'kg/m2' , [ 1 -2 0 0 0 0 0] , 1 ; ...
'kg/m3' , [ 1 -3 0 0 0 0 0] , 1 ; ...
% mass flow or structural damping
'kg/s' , [ 1 0 -1 0 0 0 0] , 1 ; ...
% structural stiffness
'kg/s2' , [ 1 0 -2 0 0 0 0] , 1 ; ...
% frequency
'Hz' , [ 0 0 -1 0 0 0 0] , 1 ; ...
'1/s' , [ 0 0 -1 0 0 0 0] , 1 ; ...
'1/min' , [ 0 0 -1 0 0 0 0] , 1/60 ; ...
% velocity
'm/s' , [ 0 1 -1 0 0 0 0] , 1 ; ...
'km/h' , [ 0 1 -1 0 0 0 0] , 1/3.6 ; ...
'kn' , [ 0 1 -1 0 0 0 0] , 0.5144 ; ... % knots
% acceleration
'm/s2' , [ 0 1 -2 0 0 0 0] , 1 ; ...
'GU' , [ 0 1 -2 0 0 0 0] , 9.81 ; ... % gravitational units
% force
'N' , [ 1 1 -2 0 0 0 0] , 1 ; ...
'dyn' , [ 1 1 -2 0 0 0 0] , 1e-5 ; ...
'p' , [ 1 1 -2 0 0 0 0] , 9.80665e-3 ; ...
% impulse
'Ns' , [ 1 1 -1 0 0 0 0] , 1 ; ...
% pressure
'Pa' , [ 1 -1 -2 0 0 0 0] , 1 ; ...
'N/m2' , [ 1 -1 -2 0 0 0 0] , 1 ; ... % e.g. modus of elasticity
'bar' , [ 1 -1 -2 0 0 0 0] , 1e-5 ; ...
'mbar' , [ 1 -1 -2 0 0 0 0] , 1e-8 ; ...
'mmHg' , [ 1 -1 -2 0 0 0 0] , 133.322 ; ...
'atm' , [ 1 -1 -2 0 0 0 0] , 1.01325 ; ...
'at' , [ 1 -1 -2 0 0 0 0] , 0.980665 ; ...
'Torr' , [ 1 -1 -2 0 0 0 0] , 101325/760 ; ...
'lb/in2' , [ 1 -1 -2 0 0 0 0] , 6895 ; ... % pounds per square inch
'psi' , [ 1 -1 -2 0 0 0 0] , 6895 ; ... % pounds per square inch
% power
'W' , [ 1 2 -3 0 0 0 0] , 1 ; ...
'VA' , [ 1 2 -3 0 0 0 0] , 1 ; ...
'PS' , [ 1 2 -3 0 0 0 0] , 735.49875 ; ...
'W/m2' , [ 1 0 -3 0 0 0 0] , 1 ; ...
% energy
'J' , [ 1 2 -2 0 0 0 0] , 1 ; ...
'kWh' , [ 1 2 -2 0 0 0 0] , 3.6e6 ; ...
'eV' , [ 1 2 -2 0 0 0 0] , 160.21892e-21 ; ...
'erg' , [ 1 2 -2 0 0 0 0] , 1e-7 ; ...
'cal' , [ 1 2 -2 0 0 0 0] , 4.1868 ; ...
'kcal' , [ 1 2 -2 0 0 0 0] , 4.1868e3 ; ...
% viscosity
'm2/s' , [ 0 2 -1 0 0 0 0] , 1 ; ...
'St' , [ 0 2 -1 0 0 0 0] , 1e-4 ; ... % Stokes
'Pas' , [ 1 -1 -1 0 0 0 0] , 1 ; ... % Pascal seconds
% heat capacity
'J/K' , [ 1 2 -2 -1 0 0 0] , 1 ; ...
% energy density
'J/m3' , [ 1 -1 -2 0 0 0 0] , 1 ; ...
% specific energy
'J/kg' , [ 0 2 -2 0 0 0 0] , 1 ; ...
% molar energy
'J/mol' , [ 1 2 -2 0 0 0 -1] , 1 ; ...
% molar heat capacity
'J/molK' , [ 1 2 -2 -1 0 0 -1] , 1 ; ...
% heat conductivity
'W/mK' , [ 1 1 -3 -1 0 0 0] , 1 ; ...
'W/m2K' , [ 1 0 -3 -1 0 0 0] , 1 ; ...
'W/m2' , [ 1 0 -3 0 0 0 0] , 1 ; ...
'W/sr' , [ 1 2 -3 0 0 0 0] , 1 ; ...
% voltage
'V' , [ 1 2 -3 0 -1 0 0] , 1 ; ...
% resistance
'ohm' , [ 1 2 -3 0 -2 0 0] , 1 ; ...
'Ohm' , [ 1 2 -3 0 -2 0 0] , 1 ; ...
% el. conductivity
'S' , [-1 -2 3 0 2 0 0] , 1 ; ... % Siemens
% el. charge
'C' , [ 0 0 1 0 1 0 0] , 1 ; ... 5 Coulomb
'Ah' , [ 0 0 1 0 1 0 0] , 3600 ; ...
% misc. electricity
'C/m3' , [ 0 -3 1 0 1 0 0] , 1 ; ...
'C/m2' , [ 0 -2 1 0 1 0 0] , 1 ; ...
'F' , [-1 -2 4 0 2 0 0] , 1 ; ... % Farad
'F/m' , [-1 -3 4 0 2 0 0] , 1 ; ...
'V/m' , [ 1 1 -3 0 -1 0 0] , 1 ; ...
'Wb' , [ 1 2 -2 0 -1 0 0] , 1 ; ... % Weber
'T' , [ 1 0 -2 0 -1 0 0] , 1 ; ... % Tesla
'H' , [ 1 2 -2 0 -2 0 0] , 1 ; ... % Henry
'H/m' , [ 1 1 -2 0 -2 0 0] , 1 ; ...
'A/m' , [ 0 -1 0 0 1 0 0] , 1 ; ...
% misc. light
'cd/m2' , [ 0 -2 0 0 0 1 0] , 1 ; ... % Candela / Quadratmeter
'sb' , [ 0 -2 0 0 0 1 0] , 1e4 ; ... % Stilb
'lm' , [ 0 0 0 0 0 1 0] , 1 ; ... % Lumen
'lx' , [ 0 -2 0 0 0 1 0] , 1 ; ... % Lux
% misc. radioactivity
'Bq' , [ 0 -1 0 0 0 0 0] , 1 ; ... % Bequerel
'Ci' , [ 0 -1 0 0 0 0 0] , 37e9 ; ... % Curie
'Gy' , [ 0 2 -2 0 0 0 0] , 1 ; ... % Gray
'rd' , [ 0 2 -2 0 0 0 0] , 0.01 ; ... % Rad
'Sv' , [ 0 2 -2 0 0 0 0] , 1 ; ... % Sievert
'mSv' , [ 0 2 -2 0 0 0 0] , 1e-3 ; ... % miliSievert
'Rem' , [ 0 2 -2 0 0 0 0] , 0.01 ; ... % Rem
'Gy/s' , [ 0 2 -3 0 0 0 0] , 1 ; ... % Gray / Second
'rd/s' , [ 0 2 -3 0 0 0 0] , 0.01 ; ... % Rad / Second
'Sv/s' , [ 0 2 -3 0 0 0 0] , 1 ; ... % Sievert / Second
'rem/s' , [ 0 2 -3 0 0 0 0] , 0.01 ; ... % Rem / Second
'C/kg' , [-1 0 1 0 1 0 0] , 1 ; ... % Coulomb / kilogram
'R' , [-1 0 1 0 1 0 0] , 258e-6; ... % Rntgen
% misc. amount of substance
'mol/l' , [ 0 -3 0 0 0 0 1] , 1e3 ; ... % mol / liter
'l/mol' , [ 0 3 0 0 0 0 -1] , 1e-3 ; ... % liter / mol
'g/mol' , [ 1 0 0 0 0 0 -1] , 1e-3 ; ... % gramm / mol
'J/molK' , [ 1 2 -2 -1 0 0 -1] , 1 ; ... % Joule / (mol Kelvin)
'J/mol' , [ 1 2 -2 0 0 0 -1] , 1 ; ... % Joule / mol
'kg/l' , [ 1 -3 0 0 0 0 0] , 1e3 ... % kilogramm / liter
};
if isstr(Units)
if strcmpi(Units,'help')
Dimension = TM;
Factor = [];
return;
else
tmp = Units; clear Units; Units{1} = tmp;
end
end
for ii=1:length(Units)
N = {TM{:,1}};
jj = strmatch(Units{ii},N,'exact');
if isequal(jj,[])
% warning(['unit ' Units{ii} ' not in database']);
% break;
Dimension(:,ii) = zeros(1,7)';
Factor(ii) = 1;
else
Dimension(:,ii) = TM{jj,2}';
Factor(ii) = TM{jj,3};
end
end
Factor = Factor';