Mercurial > hg > camir-aes2014
comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/@mirscalar/display.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function display(s,varargin) | |
2 % SCALAR/DISPLAY display the values of a scalar object | |
3 disp(' '); | |
4 p = get(s,'Pos'); | |
5 v = get(s,'Data'); | |
6 m = get(s,'Mode'); | |
7 t = get(s,'Title'); | |
8 n = get(s,'Name'); | |
9 n2 = get(s,'Name2'); | |
10 u = get(s,'Unit'); | |
11 fp = get(s,'FramePos'); | |
12 pp = get(s,'PeakPos'); | |
13 leg = get(s,'Legend'); | |
14 legm = get(s,'MultiData'); | |
15 cha = get(s,'Channels'); | |
16 for i = 1:length(v) % For each audio file | |
17 vi = v{i}; | |
18 if isempty(m) | |
19 mi = []; | |
20 else | |
21 mi = m{i}; | |
22 end | |
23 fpi = fp{i}; | |
24 if isempty(pp) | |
25 ppi = []; | |
26 else | |
27 ppi = pp{i}; | |
28 end | |
29 | |
30 if isempty(vi) | |
31 disp(['The ',t,' related to file ',n{i},... | |
32 ' does not contain any data.']); | |
33 return | |
34 end | |
35 | |
36 %if iscell(ppi) | |
37 % ppi = ppi{i}; | |
38 %end | |
39 | |
40 if size(vi,1) == 1 && size(vi,2) == 1 && size(vi,3) == 1 && ... | |
41 (not(iscell(vi)) || (size(vi{1},1) == 1 && ... | |
42 size(vi{1},2) == 1 && size(vi{1},3) == 1)) && ... | |
43 (not(iscell(vi{1})) || (size(vi{1}{1},1) == 1 && ... | |
44 size(vi{1}{1},2) == 1 && size(vi{1},3) == 1)) | |
45 % Simple results, returned directly in the Command Window | |
46 | |
47 if iscell(vi) | |
48 vi = vi{1}; % There is only one segment, so let's look at it | |
49 if not(isempty(mi)) | |
50 mi = mi{1}; | |
51 end | |
52 end | |
53 if iscell(vi) | |
54 if size(vi,2) > 1 | |
55 error('BUG IN DISPLAY'); %test if this condition exists | |
56 end | |
57 vi = vi{1}; % There is only one frame, so let's look at it | |
58 if not(isempty(mi)) | |
59 mi = mi{1}; | |
60 end | |
61 end | |
62 if size(vi,1) == 1 && size(vi,3) == 1 | |
63 if isempty(leg) | |
64 r = num2str(vi); | |
65 else | |
66 r = leg{vi}; | |
67 end | |
68 if not(isempty(mi)) | |
69 u = legm{mi}; | |
70 end | |
71 if strcmp(u,'/1') | |
72 u = ''; | |
73 end | |
74 if strcmp(r,'NaN') | |
75 r = 'undefined'; | |
76 u = ''; | |
77 end | |
78 if not(isempty(n2)) | |
79 disp(['The ',t,' between files ',n{1},' and ',n2{i},... | |
80 ' is ',r,' ',u]); | |
81 else | |
82 disp(['The ',t,' related to file ',n{i},' is ',r,' ',u]); | |
83 end | |
84 else | |
85 vi = squeeze(vi); | |
86 disp(['The ',t,' related to file ',n{i},' are:']); | |
87 for j = 1:size(vi,1) | |
88 if isempty(leg) | |
89 r = num2str(vi(j)); | |
90 else | |
91 r = leg{vi(j)}; | |
92 end | |
93 if not(isempty(mi)) | |
94 u = legm{mi(j)}; | |
95 end | |
96 if strcmp(r,'NaN') | |
97 r = 'undefined'; | |
98 u = ''; | |
99 end | |
100 disp(['Value #',num2str(j),': ',r,' ',u]); | |
101 end | |
102 end | |
103 | |
104 else | |
105 %Graphical display | |
106 figure | |
107 | |
108 if not(iscell(vi)) | |
109 vi = {vi}; | |
110 fpi = {fpi}; | |
111 ppi = {ppi}; | |
112 end | |
113 | |
114 nl = size(vi{1},1); % Number of bins | |
115 nc = size(vi{1},2); % Number of frames | |
116 l = size(vi{1},3); % Number of channels | |
117 il = (1-0.15)/l; | |
118 | |
119 if nc==1 && l>1 % If one frame and several channels | |
120 xlab = 'Channels'; % channels will be represented in the x axis | |
121 l = 1; | |
122 else | |
123 xlab = 'Temporal location of events (in s.)'; | |
124 end | |
125 | |
126 varpeaks = 0; % Variable data size over frames? | |
127 if iscell(vi{1}) | |
128 for j = 1:length(vi) | |
129 for k = 1:l | |
130 for h = 1:size(vi{j},2) | |
131 if length(vi{j}{1,h,k}) > 1 | |
132 varpeaks = 1; | |
133 end | |
134 end | |
135 end | |
136 end | |
137 if not(varpeaks) | |
138 for j = 1:length(vi) | |
139 vj = zeros(size(vi{j})); | |
140 for k = 1:l | |
141 for h = 1:size(vi{j},2) | |
142 if isempty(vi{j}{1,h,k}) | |
143 vj(1,h,k) = NaN; | |
144 else | |
145 vj(1,h,k) = vi{j}{1,h,k}; | |
146 end | |
147 end | |
148 end | |
149 vi{j} = vj; | |
150 end | |
151 end | |
152 end | |
153 | |
154 if varpeaks % Peaks displayed with diamonds | |
155 diamond = 1; | |
156 set(gca,'NextPlot','replacechildren') | |
157 hold on | |
158 else | |
159 diamond = 0; | |
160 hold all | |
161 end | |
162 | |
163 for k = 1:l % For each channel | |
164 if l>1 | |
165 subplot('Position',[0.1 (k-1)*il+0.1 0.89 il-0.02]) | |
166 end | |
167 hold on | |
168 | |
169 vold = NaN; % Buffers used to link curves between segments | |
170 fold = NaN; | |
171 | |
172 for j = 1:length(vi) % for each segment | |
173 vj = vi{j}; | |
174 | |
175 fpj = fpi{j}; | |
176 if isempty(ppi) || length(ppi)<j | |
177 ppj = []; | |
178 else | |
179 ppj = ppi{j}; | |
180 end | |
181 | |
182 if strcmp(xlab,'Channels') | |
183 %vj = squeeze(vj); % does not work with lowenergy | |
184 %ppj = squeeze(ppj); | |
185 vj = shiftdim(vj,1); | |
186 ppj = shiftdim(ppj,1); | |
187 fpj = cha{i}; | |
188 end | |
189 | |
190 minvi = Inf; % The limits of the rectangle bordering segments | |
191 maxvi = -Inf; | |
192 | |
193 if diamond | |
194 % Variable data size for each frame | |
195 legobj = []; | |
196 legval = []; | |
197 | |
198 if not(strcmp(xlab,'Channels')) | |
199 if iscell(fpi(1,j)) | |
200 fpj = fpi{j}; | |
201 else | |
202 error('BUG IN DISPLAY'); %test if this condition exists | |
203 fpj = fpi(:,j); | |
204 end | |
205 end | |
206 | |
207 for h = 1:size(vj,2) % for each frame | |
208 if not(isempty(vj{1,h,k})) | |
209 if isempty(mi) | |
210 % No use of legends | |
211 if not(isempty(vj{1,h,k})) | |
212 plot(mean(fpj(:,h),1),vj{1,h,k},'d',... | |
213 'LineWidth',2,'MarkerFaceColor','b'); | |
214 end | |
215 | |
216 else | |
217 % Use of legends | |
218 mj = mi{j}{1,h,k}; | |
219 lmj = length(mj); | |
220 for kk = 1:lmj | |
221 handle = plot(mean(fpj(:,h),1),vj{1,h,k}(kk),'d',... | |
222 'Color',num2col(mj(kk)),... | |
223 'MarkerSize',7+(lmj-kk)*2,... | |
224 'MarkerFaceColor',num2col(mj(kk))); | |
225 if isempty(find(legval == mj(kk))) | |
226 legval = [legval mj(kk)]; | |
227 legobj = [legobj handle]; | |
228 end | |
229 end | |
230 end | |
231 | |
232 %if not(isempty(ppi)) ... % Peaks display | |
233 %&& not(isempty(find(ppi{1} == j))) | |
234 % plot(mean(fpj(:,h),1),vj{1,h,k},'+r') | |
235 %end | |
236 end | |
237 | |
238 if not(isempty(vj{1,h,k})) | |
239 minvi = min(minvi,min(vj{1,h,k})); | |
240 maxvi = max(maxvi,max(vj{1,h,k})); | |
241 end | |
242 end | |
243 | |
244 if (exist('legm') == 1) && not(isempty(legm)) | |
245 legend(legobj,legm{legval},'Location','Best') | |
246 end | |
247 | |
248 else | |
249 % Constant data size along frames | |
250 | |
251 for h = 1:nl % For each dimension represented | |
252 %if not(isempty(vj(h,:,k))) | |
253 if isnan(vold) | |
254 plot(mean(fpj,1),vj(h,:,k)',... | |
255 '+-','Color',num2col(h)) | |
256 else | |
257 plot([fold mean(fpj,1)],[vold(h) vj(h,:,k)]',... | |
258 '+-','Color',num2col(h)) | |
259 % Current curve linked with curve from | |
260 % previous segment | |
261 end | |
262 if h == nl | |
263 if isempty(vj) | |
264 vold = NaN; | |
265 fold = NaN; | |
266 else | |
267 vold = vj(:,end,k); | |
268 fold = mean(fpj(:,end),1); | |
269 end | |
270 end | |
271 % else | |
272 % vold = NaN; | |
273 % fold = NaN; | |
274 % end | |
275 end | |
276 | |
277 if not(isempty(ppj)) % Peaks display | |
278 for h = 1:nl; | |
279 ppj = ppj{1,h,k}; | |
280 plot(mean(fpj(:,ppj)),vj(h,ppj,k),'or') | |
281 end | |
282 end | |
283 | |
284 minvi = min(minvi,min(min(vj(h,:,k)))); | |
285 maxvi = max(maxvi,max(max(vj(h,:,k)))); | |
286 end | |
287 | |
288 if length(vi)>1 && size(vj,2)>1 && minvi<Inf && maxvi>-Inf | |
289 % Display of the segment rectangle | |
290 rectangle('Position',[fpj(1),minvi,... | |
291 fpj(end)-fpj(1),maxvi-minvi]+1e-16,... | |
292 'EdgeColor',num2col(j),'Curvature',.1,'LineWidth',1) | |
293 end | |
294 end | |
295 if k == l | |
296 title([t,', ',n{i}]) | |
297 end | |
298 if k == 1 | |
299 xlabel(xlab) | |
300 end | |
301 if not(isempty(leg)) | |
302 set(gca,'ytick',(1:length(leg))) | |
303 set(gca,'yticklabel',leg); | |
304 end | |
305 if l > 1 | |
306 pos = get(gca,'Position'); | |
307 hfig = axes('Position',[pos(1)-.05 pos(2)+pos(4)/2 .01 .01],... | |
308 'Visible','off'); | |
309 text(0,0,num2str(cha{i}(k)),'FontSize',12,'Color','r') | |
310 end | |
311 end | |
312 if i == 1 | |
313 if strcmp(u,'/1') | |
314 u = ' (between 0 and 1)'; | |
315 elseif isempty(u) | |
316 u = ''; | |
317 else | |
318 u = [' (in ',u,')']; | |
319 end | |
320 end | |
321 ylabel(['coefficient value', u]) | |
322 if nl>1 | |
323 legnd = cell(nl,1); | |
324 for j = 1:nl | |
325 if isempty(p) | |
326 legnd{j} = num2str(j); | |
327 else | |
328 legnd{j} = p{i}{1}{j}; | |
329 end | |
330 end | |
331 legend(legnd,'Location','Best') | |
332 end | |
333 fig = get(0,'CurrentFigure'); | |
334 disp(['The ',t,' related to file ',n{i},... | |
335 ' is displayed in Figure ',num2str(fig),'.']); | |
336 if nargin>1 | |
337 saveas(fig,[n{i},varargin{1}]); | |
338 disp(['and is saved in file ',n{i},varargin{1}]); | |
339 end | |
340 end | |
341 end | |
342 disp(' '); | |
343 drawnow |