Mercurial > hg > ltpda
comparison m-toolbox/classes/@unit/tolabel.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 % TOLABEL converts a unit object to LaTeX string suitable for use as axis labels. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: TOLABEL converts a unit object to LaTeX string suitable for | |
5 % use as axis labels. | |
6 % | |
7 % CALL: lbl = tolabel(u) | |
8 % | |
9 % VERSION: $Id: tolabel.m,v 1.9 2011/02/18 16:48:55 ingo Exp $ | |
10 % | |
11 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
12 | |
13 function varargout = tolabel(varargin) | |
14 | |
15 objs = [varargin{:}]; | |
16 | |
17 pstrs = {}; | |
18 | |
19 for ii = 1:numel(objs) | |
20 u = objs(ii); | |
21 | |
22 [num, den] = factor(u); | |
23 | |
24 numstr = formatUnit(num); | |
25 denstr = formatUnit(den); | |
26 | |
27 if isempty(denstr) | |
28 str =['$$\left[' numstr ' \right]$$']; | |
29 else | |
30 if isempty(numstr) | |
31 str =['$$\left[1/' denstr ' \right]$$']; | |
32 else | |
33 str =['$$\left[\frac{' numstr '}{' denstr '} \right]$$']; | |
34 end | |
35 end | |
36 | |
37 pstrs = [pstrs {str}]; | |
38 | |
39 end | |
40 | |
41 varargout{1} = pstrs; | |
42 end | |
43 | |
44 | |
45 function s = formatUnit(u) | |
46 | |
47 s = ''; | |
48 for kk=1:numel(u.strs) | |
49 prefix = unit.val2prefix(u.vals(kk)); | |
50 if u.exps(kk) == 0.5 | |
51 s = [s '\,{\sqrt{\textrm{' prefix u.strs{kk} '}}}']; | |
52 elseif u.exps(kk) == 1 | |
53 s = [s '\,{\textrm{' prefix u.strs{kk} '}}']; | |
54 elseif u.exps(kk) > 0 | |
55 [n,d] = rat(u.exps(kk)); | |
56 if d == 1 | |
57 s = [s '\,{\textrm{' prefix u.strs{kk} '}}^{' num2str(n) '}']; | |
58 else | |
59 s = [s '\,{\textrm{' prefix u.strs{kk} '}}^{' num2str(n) '/' num2str(d) '}']; | |
60 end | |
61 end | |
62 end | |
63 | |
64 end | |
65 |