comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/displot.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 res = displot(x,y,xlab,ylab,t,fp,pp,tp,tv,ch,multidata,pm,ap,rp,cl)
2 % graphical display of any data (except mirscalar data) computed by MIRToolbox
3
4 %opengl('OpenGLWobbleTesselatorBug',1)
5 % Rendering complex patch object may cause segmentation violation and
6 % return a tesselator error message in the stack trace. This command
7 % enables a workaround of that bug that might work sometimes...
8
9 if isempty(y)
10 res = 0;
11 return
12 end
13 manychannels = 0;
14 y1 = y{1};
15 if length(y) == 1
16 y = y{1};
17 if length(x) == 1
18 x = x{1};
19 end
20 end
21 if isempty(y)
22 res = 0;
23 return
24 end
25
26 if isstruct(cl)
27 y = cl.centr(:,cl.index);
28 end
29
30 figure
31 fp2 = uncell(fp);
32 c = size(y,2);
33 lx = size(y,1);
34 l = size(y1,3); % Number of channels
35 il = (1-0.15)/l;
36
37 if iscell(y)
38 if size(y{1},3) > 1 && size(y{1},1) == 1
39 for j = 1:c
40 y{j} = reshape(y{j},size(y{j},2),size(y{j},3));
41 y{j} = y{j}';
42 end
43 lx = l;
44 l = 1;
45 end
46 else
47 if l > 1 && lx == 1
48 y = reshape(y,size(y,2),size(y,3));
49 y = y';
50 x = repmat(ch,[1 size(y,2) size(y,3)]);
51 lx = l;
52 l = 1;
53 end
54 end
55 if not(iscell(y)) && l > 20 %&& size(y,3) == 1
56 manychannels = 1;
57 if lx == 1
58 y = reshape(y,[c l])';
59 lx = l;
60 l = 1;
61 else
62 y = reshape(y,[lx l])';
63 fp = reshape(x,[1 lx size(x,3)]);
64 fp = fp(:,:,1);
65 fp2 = fp;
66 c = l;
67 l = 1;
68 x = ch';
69 end
70 end
71 curve = (not(iscell(y)) && not(isequal(fp2,0)) && size(fp2,2)==1) || ...
72 ...%(iscell(y) && size(y{1}) == 1) || ...
73 c == 1 || (strcmp(xlab,'time (s)') && not(manychannels));
74 if curve
75 for i = 1:l
76 if l>1
77 subplot(l,1,l-i+1,'align');
78 end
79 if not(iscell(y))
80 y = {y};
81 x = {x};
82 end
83 col = cell(length(y));
84 for h = 1:length(y)
85 col{h} = zeros(size(y{h},2),3,size(y{h},4));
86 for j = 1:size(y{h},2)
87 if ischar(x{h})
88 xj = x{h};
89 else
90 xj = x{h}(:,j);
91 end
92 yj = y{h}(:,j,i,:);
93 lk = size(yj,4);
94 for k = 1:lk
95 if c > 1
96 col{h}(j,:,k) = rand(1,3);
97 else
98 col{h}(j,:,k) = num2col(k);
99 end
100 yk = yj(:,:,:,k);
101 if not(isempty(yk))
102 if iscell(xj)
103 lj = length(xj);
104 abs = 0:lj-1;
105 elseif ischar(xj)
106 abs = 1:length(yk);
107 else
108 abs = xj;
109 end
110 if length(abs) < 20 && lk == 1 && c == 1
111 bar(abs,yk);
112 else
113 plot(abs,yk,'Color',col{h}(j,:,k));
114 end
115 if iscell(xj)
116 tick = 0:ceil(lj/14):lj-1;
117 set(gca,'xtick',tick);
118 set(gca,'xticklabel',xj(tick+1));
119 elseif ischar(xj)
120 set(gca,'xticklabel',x);
121 end
122 hold on
123 end
124 end
125 end
126 if length(y) > 1
127 if isempty(cl)% || isempty(cl{1}) ... this because of a bug..
128 %|| isempty(cl{i})
129 colr = h;
130 %elseif iscell(cl{i})
131 % colr = cl{i}(h);
132 elseif length(cl) == 1
133 colr = cl;
134 else
135 colr = cl(h); %cl{i}(h);
136 end
137 if not(isempty(x{h}))
138 rectangle('Position',[x{h}(1),...
139 min(min(y{h}(:,:,i))),...
140 x{h}(end)-x{h}(1),...
141 max(max(y{h}(:,:,i)))-...
142 min(min(y{h}(:,:,i)))]+1e-16,...
143 'EdgeColor',num2col(colr),'Curvature',.1,'LineWidth',1)
144 end
145 end
146 end
147 if not(isempty(multidata))
148 legend(multidata{:},'Location','Best')
149 end
150 for h = 1:length(y)
151 for j = 1:size(y{h},2)
152 xj = x{h}(:,j);
153 yj = y{h}(:,j,i,:);
154 lk = size(yj,4);
155 for k = 1:lk
156 yk = yj(:,:,:,k);
157 if not(isempty(yk))
158 if size(y{h},2) > 1
159 rectangle('Position',[xj(1),min(yk),...
160 xj(end)-xj(1),max(yk)-min(yk)]+1e-16,...
161 'EdgeColor',col{h}(j,:,k))
162 end
163 if not(isempty(pp)) && not(isempty(pp{1}))
164 [ppj order] = sort(pp{h}{1,j,i});
165 if not(isempty(pm)) && not(isempty(pm{1}))
166 pmj = pm{h}{1,j,i}(order);
167 [R C] = find(pmj==k);
168 if iscell(xj)
169 plot(ppj(R,C)-1,yk(ppj(R,C)),'or')
170 else
171 plot(xj(ppj(R,C)),yk(ppj(R,C)),'or')
172 end
173 else
174 if lk > 1
175 [R C] = find(ppj(:,:,2)==k);
176 plot(xj(ppj(R,C)),yk(ppj(R,C)),'or')
177 else
178 plot(xj(ppj),yk(ppj),'or')
179 end
180 end
181 if not(isempty(ap)) && not(isempty(ap{1}))
182 apj = ap{h}{1,j,i};
183 plot(xj(apj),yk(apj),'dr')
184 for g = 1:length(apj)
185 line([xj(ppj(g)),xj(apj(g))],...
186 [yk(ppj(g)),yk(apj(g))],...
187 'Color','r')
188 end
189 end
190 if not(isempty(rp)) && not(isempty(rp{1}))
191 rpj = rp{h}{1,j,i};
192 plot(xj(rpj),yk(rpj),'dr')
193 for g = 1:length(rpj)
194 line([xj(ppj(g)),xj(rpj(g))],...
195 [yk(ppj(g)),yk(rpj(g))],...
196 'Color','r')
197 end
198 end
199 end
200 end
201 end
202 end
203 end
204 if i == l
205 title(t)
206 end
207 if i == 1
208 xlabel(xlab)
209 end
210 if l > 1
211 %if iscell(x)
212 % num = x{i}(1);
213 %else
214 num = ch(i);
215 %end
216 pos = get(gca,'Position');
217 axes('Position',[pos(1)-.05 pos(2)+pos(4)/2 .01 .01],'Visible','off');
218 text(0,0,num2str(num),'FontSize',12,'Color','r')
219 end
220 end
221 else
222 % 2-dimensional image
223 displayseg = 0;
224 if iscell(x) && ischar(x{1})
225 if size(y,4) > 1 || size(y,1) > size(x,1)
226 ticky = 0.5:23.5;
227 tickylab = {'CM','C#M','DM','D#M','EM','FM','F#M',...
228 'GM','G#M','AM','A#M','BM','Cm','C#m','Dm','D#m','Em',...
229 'Fm','F#m','Gm','G#m','Am','A#m','Bm'};
230 else
231 ticky = (1:size(x,1))';
232 tickylab = x;
233 displayseg = 1;
234 end
235 x = (1:size(y,1))';
236 elseif iscell(x) && iscell(x{1}) && ischar(x{1}{1})
237 if size(y{1},4) > 1
238 ticky = 0.5:23.5;
239 tickylab = {'CM','C#M','DM','D#M','EM','FM','F#M',...
240 'GM','G#M','AM','A#M','BM','Cm','C#m','Dm','D#m','Em',...
241 'Fm','F#m','Gm','G#m','Am','A#m','Bm'};
242 else
243 ticky = (1:size(x{1},1))';
244 tickylab = x{1};
245 displayseg = 1;
246 end
247 for i = 1:length(x)
248 x{i} = (1:size(x{i},1))';
249 end
250 else
251 ticky = [];
252 end
253 if iscell(y)
254 displayseg = 1;
255 for i = 1:l
256 if l>1
257 subplot(l,1,l-i+1,'align');
258 % subplot('Position',[0.1 (i-1)*il+0.1 0.89 il-0.02])
259 end
260 hold on
261 %surfplot(segt,x{1},repmat(x{1}/x{1}(end)*.1,[1,length(segt)]));
262 if length(x)==1 && length(y)>1
263 for k = 2:length(y)
264 x{k} = x{1};
265 end
266 end
267 for j = 1:length(x)
268 if length(x{j}) > 1
269 if size(x{j},1) == 1 && size(x{j},3) > 1
270 x{j} = reshape(x{j},size(x{j},2),size(x{j},3))';
271 mel = 1;
272 else
273 mel = 0;
274 end
275 xx = zeros(size(x{j},1)*size(y{j},4),1); %,size(x{j},2));
276 yy = zeros(size(y{j},1)*size(y{j},4),size(y{j},2));
277 for k = 1:size(y{j},4)
278 xx((k-1)*size(x{j},1)+1:k*size(x{j},1),1) = x{j}(:,1);
279 yy((k-1)*size(y{j},1)+1:k*size(y{j},1),:) = y{j}(:,:,i,k);
280 end
281 if size(y{j},4) == 1 && not(mel)
282 xxx = [1.5*xx(1,1)-0.5*xx(2,1);...
283 (xx(1:end-1)+xx(2:end))/2;...
284 1.5*xx(end,1)-0.5*xx(end-1,1)];
285 else
286 xxx = (0:size(yy,1))';
287 end
288 if size(fp{j},2) > 1
289 segt = [fp{j}(1,1),...
290 mean([fp{j}(2,1:end-1);fp{j}(1,2:end)]),...
291 fp{j}(2,end)];
292 else
293 segt = fp{j}';
294 end
295 surfplot(segt,xxx,yy(:,:));
296 if not(isempty(ticky))
297 set(gca,'ytick',ticky);
298 set(gca,'yticklabel',tickylab);
299 end
300 set(gca,'YDir','normal')
301 if (exist('pp') == 1) && not(isempty(pp))
302 if not(isempty(pp{j}))
303 for k = 1:length(pp{j})
304 ppj = pp{j}{k};
305 if size(ppj,3) == 2
306 ppj(:,:,1) = ppj(:,:,1) + (ppj(:,:,2)-1)*size(x,1);
307 ppj(:,:,2) = [];
308 plot(mean(fp{j}(:,k)),ppj-.5,'+w')
309 elseif 0 %(exist('pm') == 1) && not(isempty(pm))
310 pmj = pm{k}{1,1,i};
311 ppj(:,:) = ppj(:,:) + (pmj(:,:)-1)*size(x,1);
312 plot(mean(fp{j}(:,k)),ppj-.5,'+w') % fp shows segmentation points
313 elseif not(isempty(ppj))
314 plot(mean(fp{j}(:,k)),xx(ppj),'+k')
315 end
316 end
317 end
318 end
319 end
320 end
321 if i == l
322 title(t)
323 end
324 if i == 1
325 if manychannels
326 xlabel(xlab);
327 elseif displayseg
328 xlabel('time axis (in s.)');
329 else
330 xlabel('temporal location of beginning of frame (in s.)');
331 end
332 end
333 if l > 1
334 num = ch(i);
335 pos = get(gca,'Position');
336 axes('Position',[pos(1)-.05 pos(2)+pos(4)/2 .01 .01],'Visible','off');
337 text(0,0,num2str(num),'FontSize',12,'Color','r')
338 end
339 end
340 y = y{1};
341 else
342 mel = 0;
343 if iscell(x)
344 x = x{1};
345 end
346 if size(x,1) == 1 && size(y,1) > 1
347 if size(x,3) == 1
348 x = x';
349 else
350 mel = 1;
351 end
352 end
353 if not(isempty(pp)) && iscell(pp{1})
354 pp = pp{1};
355 pm = pm{1};
356 end
357 for i = 1:l
358 if l>1
359 subplot('Position',[0.1 (i-1)*il+0.1 0.89 il-0.02])
360 end
361 xx = zeros(size(x,1)*size(y,4),1); %,size(x,2));
362 yy = zeros(size(y,1)*size(y,4),size(y,2));
363 for k = 1:size(y,4)
364 xx((k-1)*size(x,1)+1:k*size(x,1),1) = x(:,1);
365 yy((k-1)*size(y,1)+1:k*size(y,1),:) = y(:,:,i,k);
366 end
367 if iscell(fp)
368 fp = uncell(fp);
369 end
370 lx = length(xx);
371 if lx < 6
372 curve = 1;
373 ttt = (fp(1,:)+fp(2,:))/2;
374 plot(ttt,yy)
375 if i == 1
376 legdata = cell(1,lx);
377 if strcmp(xlab(end),'s')
378 xlab(end) = [];
379 end
380 for j = 1:lx
381 legdata{j} = [xlab,' ',num2str(j)];
382 end
383 legend(legdata)
384 end
385 else
386 ttt = [fp(1,:) 2*fp(1,end)-fp(1,end-1)];
387 if size(y,4) == 1 && not(mel)
388 xxx = [1.5*xx(1)-0.5*xx(2);...
389 (xx(1:end-1)+xx(2:end))/2;...
390 1.5*xx(end)-0.5*xx(end-1)];
391 else
392 xxx = (0:size(yy,1))';
393 end
394 surfplot(ttt,xxx,yy);
395 if not(isempty(ticky))
396 set(gca,'ytick',ticky);
397 set(gca,'yticklabel',tickylab);
398 end
399 set(gca,'YDir','normal');
400 end
401 hold on
402 %if iscell(pp)
403 % pp = uncell(pp);
404 % if iscell(pm)
405 % pm = uncell(pm);
406 % end
407 %end
408 if (exist('tp') == 1) && not(isempty(tp))
409 tp = tp{i}{1};
410 tv = tv{i}{1};
411 for k = 1:size(tp,1)
412 prej = 0;
413 for j = 1:size(tp,2)
414 if tv(k,j)
415 if prej% && not(isempty(tp(k,j)))
416 plot([(ttt(prej)+ttt(prej+1))/2,...
417 (ttt(j)+ttt(j+1))/2],...
418 [(xxx(tp(k,prej))+xxx(tp(k,prej)+1))/2,...
419 (xxx(tp(k,j))+xxx(tp(k,j)+1))/2],...
420 'k','LineWidth',1)
421 plot([(ttt(prej)+ttt(prej+1))/2,...
422 (ttt(j)+ttt(j+1))/2],...
423 [(xxx(tp(k,prej))+xxx(tp(k,prej)+1))/2,...
424 (xxx(tp(k,j))+xxx(tp(k,j)+1))/2],...
425 'w+','MarkerSize',10)
426 plot([(ttt(prej)+ttt(prej+1))/2,...
427 (ttt(j)+ttt(j+1))/2],...
428 [(xxx(tp(k,prej))+xxx(tp(k,prej)+1))/2,...
429 (xxx(tp(k,j))+xxx(tp(k,j)+1))/2],...
430 'kx','MarkerSize',10)
431 end
432 prej = j;
433 end
434 end
435 end
436 elseif (exist('pp') == 1) && not(isempty(pp))
437 if size(pp,3) == l
438 for j = 1:size(pp,2)
439 ppj = pp{1,j,i};
440 if (exist('pm') == 1)
441 pmj = pm{1,j,i};
442 else
443 pmj = [];
444 end
445 if iscell(ppj)
446 ppj = uncell(ppj);
447 if iscell(pmj)
448 pmj = uncell(pmj);
449 end
450 end
451 if size(ppj,3) == 2
452 ppj(:,:,1) = ppj(:,:,1) + (ppj(:,:,2)-1)*size(x,1);
453 ppj(:,:,2) = [];
454 %plot((fp(1,j)+fp(2,j))/2,ppj-.5,'+w')
455 plot((ttt(j)+ttt(j+1))/2,(xxx(ppj)+xxx(ppj+1))/2,'+w')
456 else
457 if not(isempty(pmj))
458 ppj(:,:,:) = ppj(:,:,:) + (pmj(:,:,:)-1)*size(x,1);
459 end
460 if not(isempty(ppj))
461 %plot((segt(j)+segt(j+1))/2,xx(ppj),'+k','MarkerSize',10)
462 plot((ttt(j)+ttt(j+1))/2,(xxx(ppj)+xxx(ppj+1))/2,'+w','MarkerSize',10)
463 end
464 end
465 end
466 else
467 for j = 1:size(pp,3)
468 ppj = pp{1,1,j};
469 if (exist('pm') == 1)
470 pmj = pm{1,1,j};
471 else
472 pmj = [];
473 end
474 if not(isempty(ppj))
475 %plot((segt(j)+segt(j+1))/2,xx(ppj),'+k','MarkerSize',10)
476 plot((ttt(ppj)+ttt(ppj+1))/2,(xxx(j)+xxx(j+1))/2,'+w','MarkerSize',10)
477 end
478 end
479 end
480 end
481 if i == l
482 title(t)
483 end
484 if i == 1
485 xlabel('time axis (in s.)');
486 end
487 if l > 1
488 if iscell(x)
489 num = x{i}(1);
490 else
491 num = ch(i);
492 end
493 pos = get(gca,'Position');
494 hfig = axes('Position',[pos(1)-.05 pos(2)+pos(4)/2 .01 .01],'Visible','off');
495 text(0,0,num2str(num),'FontSize',12,'Color','r')
496 end
497 end
498 end
499 end
500 if l == 1
501 if curve
502 %if (exist('dbv') == 1) && dbv
503 % ylabel([ylab ' (logarithmic scale)']);
504 %else
505 ylabel(ylab);
506 %end
507 elseif manychannels
508 ylabel('Channels');
509 else
510 ylabel(xlab)
511 end
512 end
513 res = 1;
514 drawnow