1 | %PLOTOPTIONS class definition
|
---|
2 | %
|
---|
3 | % Usage:
|
---|
4 | % plotoptions = plotoptions(varargin)
|
---|
5 |
|
---|
6 | classdef plotoptions
|
---|
7 | properties (SetAccess=public)
|
---|
8 | % {{{1
|
---|
9 | numberofplots = 0;
|
---|
10 | figurenumber = 1;
|
---|
11 | list = cell(0,0);
|
---|
12 | %}}}
|
---|
13 | end
|
---|
14 | methods
|
---|
15 | function opt=plotoptions(varargin) % {{{1
|
---|
16 | opt=buildlist(opt,varargin{:});
|
---|
17 | end
|
---|
18 | %}}}
|
---|
19 | function disp(opt) % {{{1
|
---|
20 | disp(sprintf('\n%s = \n',inputname(1)));
|
---|
21 | disp(sprintf(' numberofplots: %i',opt.numberofplots));
|
---|
22 | disp(sprintf(' figurenumber: %i',opt.figurenumber));
|
---|
23 | if ~isempty(opt.list),
|
---|
24 | disp(sprintf(' list: (%ix%i)',size(opt.list,1),size(opt.list,2)));
|
---|
25 | for i=1:size(opt.list,1),
|
---|
26 | unit=opt.list{i};
|
---|
27 | disp(sprintf('\n options of plot number %i',i));
|
---|
28 | for j=1:size(unit.list,1)
|
---|
29 | if ischar(unit.list{j,2}),
|
---|
30 | disp(sprintf(' field: %-10s value: ''%s''',unit.list{j,1},unit.list{j,2}));
|
---|
31 | elseif isnumeric(unit.list{j,2}) & length(unit.list{j,2})==1,
|
---|
32 | disp(sprintf(' field: %-10s value: %g',unit.list{j,1},unit.list{j,2}));
|
---|
33 | else
|
---|
34 | disp(sprintf(' field: %-10s value: (%ix%i)',unit.list{j,1},size(unit.list{j,2},1),size(unit.list{j,2},2)));
|
---|
35 | end
|
---|
36 | end
|
---|
37 | end
|
---|
38 | else
|
---|
39 | disp(sprintf(' list: empty'));
|
---|
40 | end
|
---|
41 | end
|
---|
42 | %}}}
|
---|
43 | function opt=buildlist(opt,varargin) % {{{1
|
---|
44 |
|
---|
45 | %check length of input
|
---|
46 | if mod((nargin-1),2),
|
---|
47 | error('buildlist error message: an even number of plotoptions is required')
|
---|
48 | end
|
---|
49 |
|
---|
50 | %go through varargin and build list (like pairoptions)
|
---|
51 | rawoptions=pairoptions(varargin{:});
|
---|
52 | numoptions = (nargin-1)/2;
|
---|
53 | rawlist=cell(numoptions,2);
|
---|
54 | for i=1:numoptions,
|
---|
55 | if ischar(varargin{2*i-1}),
|
---|
56 | rawlist{i,1}=varargin{2*i-1};
|
---|
57 | rawlist{i,2}=varargin{2*i};
|
---|
58 | else
|
---|
59 | %option is not a string, ignore it
|
---|
60 | disp(['WARNING: option number ' num2str(i) ' is not a string, it will be ignored']);
|
---|
61 | rawlist(i,:)=[];
|
---|
62 | continue
|
---|
63 | end
|
---|
64 | end
|
---|
65 |
|
---|
66 | %get figure number
|
---|
67 | opt.figurenumber=getfieldvalue(rawoptions,'figure',1);
|
---|
68 |
|
---|
69 | %get number of data to be plotted
|
---|
70 | numberofplots=fieldoccurences(rawoptions,'data');
|
---|
71 | opt.numberofplots=numberofplots;
|
---|
72 |
|
---|
73 | %figure out wether alloptions flog is on
|
---|
74 | if strcmpi(getfieldvalue(rawoptions,'alloptions','off'),'on'),
|
---|
75 | allflag=1;
|
---|
76 | else
|
---|
77 | allflag=0;
|
---|
78 | end
|
---|
79 |
|
---|
80 | %initialize opt.list
|
---|
81 | opt.list=cell(numberofplots,1);
|
---|
82 | for i=1:numberofplots,
|
---|
83 | opt.list{i}=pairoptions;
|
---|
84 | end
|
---|
85 |
|
---|
86 | %process plot options
|
---|
87 | for i=1:size(rawlist,1),
|
---|
88 |
|
---|
89 | %If alloptions flag has is on, apply to all plots
|
---|
90 | if (allflag & ~strcmpi(rawlist{i,1},'data') & ~ismember('#',rawlist{i,1})),
|
---|
91 | for j=1:numberofplots,
|
---|
92 | opt.list{j}=addfield(opt.list{j},rawlist{i,1},rawlist{i,2});
|
---|
93 | end
|
---|
94 |
|
---|
95 | %option contains '#'
|
---|
96 | elseif ismember('#',rawlist{i,1}),
|
---|
97 |
|
---|
98 | %get suplot(s) associated
|
---|
99 | string=strsplit(rawlist{i,1},'#');
|
---|
100 | plotnums=string{end};
|
---|
101 | field=string{1};
|
---|
102 |
|
---|
103 | %divide plotnums if there is a comma ','
|
---|
104 | plotnums=strsplit_strict(plotnums,',');
|
---|
105 |
|
---|
106 | %loop over plotnums
|
---|
107 | for k=1:length(plotnums);
|
---|
108 | plotnum=plotnums{k};
|
---|
109 |
|
---|
110 | %Empty
|
---|
111 | if isempty(plotnum),
|
---|
112 | continue;
|
---|
113 |
|
---|
114 | %#all
|
---|
115 | elseif strcmpi(plotnum,'all');
|
---|
116 | for j=1:numberofplots,
|
---|
117 | opt.list{j}=addfield(opt.list{j},field,rawlist{i,2});
|
---|
118 | end
|
---|
119 |
|
---|
120 | %#i-j
|
---|
121 | elseif ismember('-',plotnum)
|
---|
122 | nums=strsplit(plotnum,'-');
|
---|
123 | if length(nums)~=2, continue; end
|
---|
124 | if ~isnumeric(nums)
|
---|
125 | error(['the option #i-j is not set properly for ' field]);
|
---|
126 | end
|
---|
127 | for j=nums(1):nums(2),
|
---|
128 | opt.list{j}=addfield(opt.list{j},field,rawlist{i,2});
|
---|
129 | end
|
---|
130 |
|
---|
131 | %#i
|
---|
132 | else
|
---|
133 | %assign to subplot
|
---|
134 | if str2num(plotnum)>numberofplots,
|
---|
135 | error(['opt error message: ' field ' cannot be assigned (' plotnum ' exceed maximum number of plot)']);
|
---|
136 | end
|
---|
137 | opt.list{str2num(plotnum)}=addfield(opt.list{str2num(plotnum)},field,rawlist{i,2});
|
---|
138 | end
|
---|
139 | end
|
---|
140 |
|
---|
141 | %assign option field to corresponding subplot
|
---|
142 | else
|
---|
143 |
|
---|
144 | %go through all subplot and assign to the first one free
|
---|
145 | j=1;
|
---|
146 | while (j<=numberofplots),
|
---|
147 | if ~exist(opt.list{j},rawlist{i,1});
|
---|
148 | opt.list{j}=addfield(opt.list{j},rawlist{i,1},rawlist{i,2});
|
---|
149 | break
|
---|
150 | else
|
---|
151 | j=j+1;
|
---|
152 | end
|
---|
153 | end
|
---|
154 | if j>numberofplots,
|
---|
155 | disp(['plot info message: too many ''' rawlist{i,1} ''' options']);
|
---|
156 | end
|
---|
157 | end
|
---|
158 | end
|
---|
159 |
|
---|
160 | %check that there is no duplicates
|
---|
161 | for i=1:numberofplots,
|
---|
162 | opt.list{i}=deleteduplicates(opt.list{i},1);
|
---|
163 | end
|
---|
164 | end
|
---|
165 | %}}}
|
---|
166 | end
|
---|
167 | end
|
---|