Mercurial > hg > ltpda
view m-toolbox/classes/@unit/toSI.m @ 22:b11e88004fca database-connection-manager
Update collection.fromRepository
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Mon, 05 Dec 2011 16:20:06 +0100 |
parents | f0afece42f48 |
children |
line wrap: on
line source
% toSI converts the units to SI. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DESCRIPTION: toSI converts the units to SI base units. % % Expand units to be combinations of % {'m', 'kg', 's', 'A', 'mol', 'cd'} % % CALL: u_out = toSI(i_in); % % VERSION: $Id: toSI.m,v 1.1 2011/03/07 17:29:57 hewitson Exp $ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function varargout = toSI(vi) % process the units and exponents v = unit; for kk=1:numel(vi.strs) s = unit(siForUnit(vi.strs{kk})); s.exps = vi.exps(kk).*s.exps; v = v.*s; end v.simplify; % Either modify the input or set the output if nargout == 0 vi.strs = v.strs; vi.exps = v.exps; vi.vals = v.vals; else varargout{1} = v; end end function s = siForUnit(u) % output == input in default case s = u; switch u case 'rad' s = 'm m^-1'; case 'sr' s = 'm^2 m^-2'; case 'Hz' s = 's^-1'; case 'N' s = 'kg m s^-2'; case 'Pa' s = 'm^-1 kg s^-2'; case 'J' s = 'kg m^2 s^-2'; case 'W' s = 'm^2 kg s^-3'; case 'C' s = 's A'; case 'V' s = 'm^2 kg s^-3 A^-1'; case 'F' s = 'm^-2 kg^-1 s^4 A^2'; case 'Ohm' s = 'm^2 kg s^-3 A^-2'; case 'S' s = 'm^-2 kg^-1 s^3 A^2'; case 'Wb' s = 'm^2 kg s^-2 A^-1'; case 'T' s = 'kg s^-2 A^-1'; case 'H' s = 'm^2 kg s^-2 A^-2'; case 'degC' s = 'K'; end end