0001 function Browse(parameter1,parameter2)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 name = mfilename;
0064
0065 default = get(0,'DefaultFigureCreateFcn');
0066 if isa(default,'function_handle'), default = func2str(default); end
0067
0068
0069 if nargin == 1 && isastring(lower(parameter1),'on','off','all','none'),
0070
0071 switch lower(parameter1),
0072 case 'on',
0073 if isempty(regexp(default,name)),
0074 set(0,'DefaultFigureCreateFcn',[name ';' default]);
0075 end
0076 help
0077 case 'off',
0078 if ~isempty(regexp(default,name)),
0079 set(0,'DefaultFigureCreateFcn',regexprep(default,[name ';'],''));
0080 end
0081 case 'all',
0082 children = get(0,'children');
0083 for i = 1:length(children),
0084 set(children(i),'WindowButtonDownFcn',@DefineSelection);
0085 set(children(i),'KeyPressFcn',@KeyPress);
0086 end
0087 case 'none',
0088 children = get(0,'children');
0089 for i = 1:length(children),
0090 set(children(i),'WindowButtonDownFcn',[]);
0091 set(children(i),'KeyPressFcn',[]);
0092 end
0093 end
0094 return
0095 end
0096
0097
0098 if ~isempty(gcbo),
0099
0100 current = get(gcbo,'CreateFcn');
0101 if isa(current,'function_handle'), current = func2str(current); end
0102 set(gcbo,'CreateFcn',regexprep(current,[name ';'],''));
0103 end
0104
0105
0106 if nargin == 0,
0107 fig = gcf;
0108 else
0109 fig = parameter1;
0110 end
0111
0112 if nargin == 2 && strcmp(lower(parameter2),'off')
0113 set(fig,'WindowButtonDownFcn',[]);
0114 set(fig,'KeyPressFcn',[]);
0115 else
0116 set(fig,'WindowButtonDownFcn',@DefineSelection);
0117 set(fig,'KeyPressFcn',@KeyPress);
0118 end
0119
0120
0121
0122
0123
0124 function help
0125
0126 disp(' ------------------------------------------------------------------------------');
0127 disp(' Browsing mode automatically enabled for new figures.');
0128 disp(' ');
0129 disp(' To browse current axes, press a key (hold SHIFT to browse all subplots):');
0130 disp(' ');
0131 disp(' left arrow move one step to the left');
0132 disp(' right arrow move one step to the right');
0133 disp(' page up move one page to the left');
0134 disp(' page down move one page to the right');
0135 disp(' home move to the beginning');
0136 disp(' end move to the end');
0137 disp(' i zoom in (halve x axis width)');
0138 disp(' o zoom out (double x axis width)');
0139 disp(' ');
0140 disp(' To graphically define new axis limits, click and drag the region of interest,');
0141 disp(' then press a key to update the axes (hold SHIFT to update all subplots):');
0142 disp(' ');
0143 disp(' x change X axis');
0144 disp(' y change Y axis');
0145 disp(' b change both axes');
0146 disp(' ');
0147 disp(' To reset the axis limits, press a key (hold SHIFT to reset all subplots):');
0148 disp(' ');
0149 disp(' CTRL+x reset X axis');
0150 disp(' CTRL+y reset Y axis');
0151 disp(' CTRL+b reset both axes');
0152 disp(' ');
0153 disp(' To copy/paste axis limits, press a key:');
0154 disp(' ');
0155 disp(' c copy current axis limits');
0156 disp(' v apply (paste) previously copied limits to current axis');
0157 disp(' ');
0158 disp(' To use a special interactive commmand, click and drag the region of interest,');
0159 disp(' then press a key:');
0160 disp(' ');
0161 disp(' m show mean and std over selected area (image only)');
0162 disp(' s show coordinates of selected area');
0163 disp(' ------------------------------------------------------------------------------');
0164
0165
0166
0167
0168
0169 function DefineSelection(fig,event)
0170
0171 if isempty(get(fig,'CurrentAxes')), return; end
0172
0173
0174 point1 = get(gca,'CurrentPoint');
0175 rbbox;
0176 point2 = get(gca,'CurrentPoint');
0177 x1 = point1(1,1);
0178 x2 = point2(1,1);
0179 xLim = [min([x1 x2]) max([x1 x2])];
0180 y1 = point1(1,2);
0181 y2 = point2(1,2);
0182 yLim = [min([y1 y2]) max([y1 y2])];
0183 set(fig,'UserData',[xLim;yLim]);
0184
0185
0186
0187
0188
0189 function KeyPress(fig,event)
0190
0191 if isempty(get(fig,'CurrentAxes')), return; end
0192
0193 if event.Key == 's',
0194 DisplaySelection(fig,event);
0195 elseif event.Key == 'm',
0196 PlotSelectionMean(fig,event);
0197 elseif event.Key == 'c',
0198 CopyAxisLimits(fig,event);
0199 elseif event.Key == 'v',
0200 PasteAxisLimits(fig,event);
0201 else
0202 ChangeLims(fig,event);
0203 end
0204
0205
0206
0207
0208
0209 function DisplaySelection(fig,event)
0210
0211 if isempty(get(fig,'CurrentAxes')), return; end
0212
0213
0214 lims = get(fig,'UserData');
0215 if isempty(lims), return; end
0216 xLim = lims(1,:);
0217 yLim = lims(2,:);
0218
0219 x1 = num2str(xLim(1));
0220 y1 = num2str(yLim(1));
0221 n = length(x1)-length(y1);
0222 spaces = repmat(' ',1,abs(n));
0223 if n < 0, x1 = [spaces x1]; else y1 = [spaces y1] ; end
0224 x2 = num2str(xLim(2));
0225 y2 = num2str(yLim(2));
0226 n = length(x2)-length(y2);
0227 spaces = repmat(' ',1,abs(n));
0228 if n < 0, x2 = [spaces x2]; else y2 = [spaces y2] ; end
0229
0230 disp(['X = [' x1 ' ' x2 '] dX = ' num2str(diff(xLim))]);
0231 disp(['Y = [' y1 ' ' y2 '] dY = ' num2str(diff(yLim))]);
0232
0233
0234
0235
0236
0237 function PlotSelectionMean(fig,event)
0238
0239 if isempty(get(fig,'CurrentAxes')), return; end
0240
0241
0242 children = get(gca,'children');
0243 img = [];
0244 for i = 1:length(children),
0245 if strcmp(get(children(i),'type'),'image'),
0246 img = children(i);
0247 end
0248 end
0249 if isempty(img), return; end
0250
0251
0252 lims = get(fig,'UserData');
0253 if isempty(lims), return; end
0254 xLim = lims(1,:);
0255 yLim = lims(2,:);
0256
0257 data = get(img,'cdata');
0258 x = get(img,'xdata');
0259 x = linspace(x(1),x(end),size(data,2));
0260 y = get(img,'ydata');
0261 y = linspace(y(1),y(end),size(data,1));
0262 xOK = x >= xLim(1) & x <= xLim(2);
0263 yOK = y >= yLim(1) & y <= yLim(2);
0264 m = mean(data(yOK,xOK),2);
0265 s = std(data(yOK,xOK),0,2);
0266 figure;
0267 PlotMean(y(yOK),m,m-s,m+s,':');
0268
0269
0270
0271
0272
0273 function CopyAxisLimits(fig,event)
0274
0275
0276 global xAxisLimits_Browse49 yAxisLimits_Browse49;
0277
0278 xAxisLimits_Browse49 = xlim;
0279 yAxisLimits_Browse49 = ylim;
0280 disp(['Copy X axis [' num2str(xAxisLimits_Browse49(1)) ' ' num2str(xAxisLimits_Browse49(2)) ']']);
0281 disp(['Copy Y axis [' num2str(yAxisLimits_Browse49(1)) ' ' num2str(yAxisLimits_Browse49(2)) ']']);
0282
0283
0284
0285
0286
0287 function PasteAxisLimits(fig,event)
0288
0289
0290 global xAxisLimits_Browse49 yAxisLimits_Browse49;
0291
0292 if ~isempty(xAxisLimits_Browse49) && ~isempty(yAxisLimits_Browse49),
0293 disp(['Paste X axis [' num2str(xAxisLimits_Browse49(1)) ' ' num2str(xAxisLimits_Browse49(2)) ']']);
0294 disp(['Paste Y axis [' num2str(yAxisLimits_Browse49(1)) ' ' num2str(yAxisLimits_Browse49(2)) ']']);
0295 xlim(xAxisLimits_Browse49);
0296 ylim(yAxisLimits_Browse49);
0297 end
0298
0299
0300
0301
0302
0303 function ChangeLims(fig,event)
0304
0305 if isempty(get(fig,'CurrentAxes')), return; end
0306
0307
0308 NONE = 0;
0309 RIGHT_PAGE = 1;
0310 LEFT_PAGE = 2;
0311 RIGHT_STEP = 3;
0312 LEFT_STEP = 4;
0313 HOME = 5;
0314 END = 6;
0315
0316
0317 children = gca;
0318 auto = false;
0319 for i = 1:length(event.Modifier),
0320 if strcmp(event.Modifier{i},'shift'),
0321
0322 children = get(fig,'children');
0323 elseif strcmp(event.Modifier{i},'control'),
0324
0325 auto = true;
0326 end
0327 end
0328
0329
0330 changeX = false;
0331 changeY = false;
0332 move = NONE;
0333 zoomX = 1;
0334 switch(event.Key),
0335 case 'x',
0336 changeX = true;
0337 case 'y',
0338 changeY = true;
0339 case 'b',
0340 changeX = true;
0341 changeY = true;
0342 case 'pagedown',
0343 move = RIGHT_PAGE;
0344 case 'pageup',
0345 move = LEFT_PAGE;
0346 case 'rightarrow',
0347 move = RIGHT_STEP;
0348 case 'leftarrow',
0349 move = LEFT_STEP;
0350 case 'home',
0351 move = HOME;
0352 case 'end',
0353 move = END;
0354 case 'i',
0355 zoomX = 0.5;
0356 case 'o',
0357 zoomX = 2;
0358 otherwise,
0359 return
0360 end
0361
0362
0363 for i = 1:length(children),
0364 type = get(children(i),'type');
0365 if strcmp(type,'axes'),
0366 if move ~= NONE,
0367
0368 x = xlim(children(i));
0369 dx = x(2)-x(1);
0370 switch(move),
0371 case RIGHT_PAGE,
0372 xLim = x+dx;
0373 case LEFT_PAGE,
0374 xLim = x-dx;
0375 case RIGHT_STEP,
0376 xLim = x+dx/10;
0377 case LEFT_STEP,
0378 xLim = x-dx/10;
0379 case HOME,
0380
0381 c = get(children(i),'children');
0382 minX = Inf;
0383 for j = 1:length(c),
0384 m = get(c(j),'xdata');
0385 minX = min([minX m(1)]);
0386 end
0387 xLim = minX + [0 dx];
0388 case END,
0389
0390 c = get(children(i),'children');
0391 maxX = -Inf;
0392 for j = 1:length(c),
0393 m = get(c(j),'xdata');
0394 maxX = max([maxX m(end)]);
0395 end
0396 xLim = maxX - [dx 0];
0397 end
0398 set(children(i),'xlim',xLim);
0399
0400 set(fig,'UserData',[]);
0401 elseif zoomX ~= 1,
0402
0403 xLim = get(children(i),'xlim');
0404 set(children(i),'xlim',[xLim(1) xLim(1)+zoomX*(xLim(2)-xLim(1))]);
0405 else
0406
0407 lims = get(fig,'UserData');
0408 if ~auto && isempty(lims), return; end
0409 if ~isempty(lims),
0410 xLim = lims(1,:);
0411 yLim = lims(2,:);
0412 end
0413
0414 if changeX,
0415 if auto,
0416 set(children(i),'xlimmode','auto');
0417 else
0418 if xLim(1) ~= xLim(2), set(children(i),'xlim',xLim); end
0419 end
0420 end
0421 if changeY,
0422 if auto,
0423 set(children(i),'ylimmode','auto');
0424 else
0425 if yLim(1) ~= yLim(2), set(children(i),'ylim',yLim); end
0426 end
0427 end
0428 end
0429 end
0430 end