comparison m-toolbox/classes/@unit/factor.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % FACTOR factorises units in to numerator and denominator units.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: FACTOR factorises units in to numerator and denominator
5 % units.
6 %
7 % CALL: [num, den] = factor(units)
8 %
9 % INPUTS: 'units' - input unit object
10 %
11 % OUTPUTS:
12 % 'num' - numerator unit object
13 % 'den' - denominator unit object
14 %
15 % CALL FOR PARAMETERS:
16 %
17 % obj.factor('INFO') % Retrieve method information
18 %
19 % VERSION: $Id: factor.m,v 1.4 2011/02/18 16:48:55 ingo Exp $
20 %
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22 function varargout = factor(varargin)
23
24 % Get unit objects
25 units = [varargin{:}];
26
27 if numel(units) ~= 1
28 error('### Please give (only) one input unit object');
29 end
30
31 if isempty(units)
32 num = [];
33 den = [];
34 else
35 % get indices
36 numi = units.exps>0;
37 deni = units.exps<0;
38 % Make input units from denominator
39 den = unit();
40 if any(deni)
41 den.strs = units.strs(deni);
42 den.exps = abs(units.exps(deni));
43 den.vals = units.vals(deni);
44 end
45 % Make output units from numerator
46 num = unit();
47 if any(numi)
48 num.strs = units.strs(numi);
49 num.exps = units.exps(numi);
50 num.vals = units.vals(numi);
51 end
52 end
53
54 if nargout == 2
55 varargout{1} = num;
56 varargout{2} = den;
57 else
58 error('### Incorrect outputs');
59 end
60
61 end
62