Mercurial > hg > ltpda
comparison m-toolbox/classes/@aoplotter/makeAxisLabel.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 % MAKEAXISLABEL makes an axis label from the given ao | |
2 % | |
3 % CALL | |
4 % [xlbl, ylbl, zlbl] = makeAxisLabel(a) | |
5 % | |
6 % M Hewitson 10-12-10 | |
7 % | |
8 % $Id: makeAxisLabel.m,v 1.1 2010/12/12 08:29:00 hewitson Exp $ | |
9 % | |
10 function [xlbl, ylbl, zlbl] = makeAxisLabel(d) | |
11 | |
12 xlbl = ''; | |
13 ylbl = ''; | |
14 zlbl = ''; | |
15 yunits = char(d.yunits); | |
16 switch class(d.data) | |
17 case 'tsdata' | |
18 xunits = char(d.xunits); | |
19 xlbl = sprintf('Time %s', xunits); | |
20 ylbl = sprintf('Amplitude %s', yunits); | |
21 case 'fsdata' | |
22 xunits = char(d.xunits); | |
23 xlbl = sprintf('Frequency %s', xunits); | |
24 ylbl = sprintf('Amplitude %s', yunits); | |
25 case 'xydata' | |
26 xunits = char(d.xunits); | |
27 xlbl = sprintf('X-Value %s', xunits); | |
28 ylbl = sprintf('Y-Value %s', yunits); | |
29 case 'cdata' | |
30 xlbl = 'Sample Number'; | |
31 ylbl = sprintf('Value %s', yunits); | |
32 case 'xyzdata' | |
33 zunits = char(d.zunits); | |
34 xlbl = sprintf('x-value %s', yunits); | |
35 ylbl = sprintf('y-value %s', yunits); | |
36 zlbl = sprintf('Value %s', zunits); | |
37 otherwise | |
38 error('unknown ao data type'); | |
39 end | |
40 | |
41 xlbl = fixlabel(xlbl); | |
42 ylbl = fixlabel(ylbl); | |
43 zlbl = fixlabel(zlbl); | |
44 | |
45 end | |
46 | |
47 function ss = fixlabel(ss) | |
48 | |
49 MAX_LENGTH = 50; | |
50 wasCell = true; | |
51 if ~iscell(ss) | |
52 ss = {ss}; | |
53 wasCell = false; | |
54 end | |
55 | |
56 for kk = 1:numel(ss) | |
57 s = ss{kk}; | |
58 if ~isempty(s) | |
59 % Replace all ^(...) with ^{...} | |
60 jj = 1; | |
61 while jj < numel(s) | |
62 if strcmp(s(jj:jj+1), '^(') | |
63 % find next ) | |
64 for k = 1:numel(s)-jj+1 | |
65 if s(jj+k) == ')' | |
66 s(jj+1) = '{'; | |
67 s(jj+k) = '}'; | |
68 break; | |
69 end | |
70 end | |
71 end | |
72 jj = jj + 1; | |
73 end | |
74 % Replace all .^ with ^ | |
75 s = strrep(s, '.^', '^'); | |
76 | |
77 % reduce size | |
78 if length(s) > MAX_LENGTH | |
79 addStr = '...'; | |
80 else | |
81 addStr = ''; | |
82 end | |
83 ssize = min(MAX_LENGTH, length(s)); | |
84 s = [s(1:ssize) addStr]; | |
85 end | |
86 ss(kk) = {s}; | |
87 end | |
88 | |
89 | |
90 if ~wasCell | |
91 ss = ss{1}; | |
92 end | |
93 | |
94 end |