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