0001 function [Xpoint,Ypoint,XYhist] = crosshair_subplots(action);
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
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112 if ~exist('action','var')
0113 action = 'init';
0114 elseif isempty(action)
0115 action = 'init';
0116 end
0117
0118 XHR_HANDLES = get(gcf,'userdata');
0119
0120 if gca & ~isempty(XHR_HANDLES),
0121 if ~isequal(gca,XHR_HANDLES.axis),
0122
0123 XHR_HANDLES.axis = gca;
0124 XHR_HANDLES.data = get_data;
0125 end
0126 end
0127
0128
0129
0130 if strcmp(action, 'keypress'),
0131
0132 CC = get(XHR_HANDLES.gui,'CurrentCharacter');
0133 cc = double(CC);
0134 if cc,
0135 switch cc,
0136 case 9, action = 'axes';
0137 case 27, action = 'done';
0138 case 28, action = 'prevx';
0139 case 29, action = 'nextx';
0140 case 30, action = 'ygt';
0141 case 31, action = 'ylt';
0142 case 13, action = 'store';
0143 otherwise, action = 'up';
0144 end
0145 end
0146 end
0147
0148
0149 action = lower(action);
0150
0151 switch action,
0152
0153 case 'init',
0154
0155
0156 XHR_HANDLES = INIT;
0157
0158
0159 XHR_HANDLES = updateDATA(XHR_HANDLES);
0160 Xpoint = get(XHR_HANDLES.xvalue,'Value');
0161 Ypoint = get(XHR_HANDLES.yvalue,'Value');
0162
0163
0164 case 'axes',
0165
0166
0167 ax = findobj(gcf,'type','axes');
0168 if length(ax) > 1,
0169 nax = find(ax == gca);
0170 if nax < length(ax),
0171 axes(ax(nax+1));
0172 else
0173 axes(ax(1));
0174 end
0175 end
0176 XHR_HANDLES.axis = gca;
0177 XHR_HANDLES.data = get_data;
0178 XHR_HANDLES = updateGUI(XHR_HANDLES);
0179 Xpoint = get(XHR_HANDLES.xvalue,'Value');
0180 Ypoint = get(XHR_HANDLES.yvalue,'Value');
0181
0182
0183 case 'down',
0184
0185 set(XHR_HANDLES.gui,'WindowButtonMotionFcn','crosshair_subplots(''move'');');
0186 set(XHR_HANDLES.gui,'WindowButtonUpFcn','[Xpoint,Ypoint] = crosshair_subplots(''up'');');
0187
0188 XHR_HANDLES = updateDATA(XHR_HANDLES);
0189 Xpoint = get(XHR_HANDLES.xvalue,'Value');
0190 Ypoint = get(XHR_HANDLES.yvalue,'Value');
0191
0192
0193
0194 case 'move',
0195
0196 XHR_HANDLES = updateDATA(XHR_HANDLES);
0197 Xpoint = get(XHR_HANDLES.xvalue,'Value');
0198 Ypoint = get(XHR_HANDLES.yvalue,'Value');
0199
0200
0201
0202 case 'up',
0203
0204 set(XHR_HANDLES.gui,'WindowButtonMotionFcn',' ');
0205 set(XHR_HANDLES.gui,'WindowButtonUpFcn',' ');
0206
0207 XHR_HANDLES = updateDATA(XHR_HANDLES);
0208 Xpoint = get(XHR_HANDLES.xvalue,'Value');
0209 Ypoint = get(XHR_HANDLES.yvalue,'Value');
0210
0211
0212
0213 case {'nextx','prevx','changex','nexty','prevy','changey','ylt','ygt'},
0214
0215 XHR_HANDLES = moveXY(XHR_HANDLES,action);
0216 Xpoint = get(XHR_HANDLES.xvalue,'Value');
0217 Ypoint = get(XHR_HANDLES.yvalue,'Value');
0218
0219
0220
0221 case 'store',
0222
0223 Xpoint = get(XHR_HANDLES.xvalue,'Value');
0224 Ypoint = get(XHR_HANDLES.yvalue,'Value');
0225 updateXYhistory(XHR_HANDLES);
0226
0227
0228 case {'done','exit'},
0229
0230 Xpoint = get(XHR_HANDLES.xvalue,'Value');
0231 Ypoint = get(XHR_HANDLES.yvalue,'Value');
0232
0233
0234 handles = fieldnames(XHR_HANDLES);
0235 for i=1:length(handles),
0236 switch handles{i},
0237 case {'axis','datalines','gui'},
0238 otherwise,
0239 h = getfield(XHR_HANDLES,handles{i});
0240 if ishandle(h), delete(h); end
0241 end
0242 end
0243
0244 if strcmp(action,'exit');
0245 if ishandle(XHR_HANDLES.gui),
0246 close(XHR_HANDLES.gui);
0247 end
0248 else
0249
0250 lines = findobj(gcf,'tag','XHR_XLINE');
0251 for l = 1:length(lines),
0252 line = lines(l);
0253 if ishandle(line), delete(line); end
0254 end
0255 lines = findobj(gcf,'tag','XHR_YLINE');
0256 for l = 1:length(lines),
0257 line = lines(l);
0258 if ishandle(line), delete(line); end
0259 end
0260
0261 set(XHR_HANDLES.gui,'WindowButtonUpFcn','');
0262 set(XHR_HANDLES.gui,'WindowButtonMotionFcn','');
0263 set(XHR_HANDLES.gui,'WindowButtonDownFcn',' ');
0264
0265 refresh(XHR_HANDLES.gui);
0266 end
0267
0268 clear XHR_HANDLES;
0269 return;
0270
0271 end
0272
0273 if ishandle(XHR_HANDLES.axis),
0274 set(XHR_HANDLES.axis,'userdata',XHR_HANDLES.data);
0275 end
0276
0277 if ishandle(XHR_HANDLES.gui),
0278 set(XHR_HANDLES.gui,'userdata',XHR_HANDLES);
0279 figure(XHR_HANDLES.gui);
0280 end
0281
0282 return;
0283
0284
0285
0286
0287
0288
0289 function updateXYhistory(H),
0290
0291 Ch = get(H.yindex,'Value');
0292 X = get(H.xvalue,'Value');
0293 Y = get(H.yvalue,'Value');
0294 fX = get(H.fxvalue,'Value');
0295 fY = get(H.fyvalue,'Value');
0296
0297 fXeq = get(H.fxeq,'String');
0298 fYeq = get(H.fyeq,'String');
0299
0300 XY.labels = {'Channel','X','Y',['f(x) = ',fXeq],['f(y) = ',fYeq]};
0301 XY.data = [Ch,X,Y,fX,fY];
0302
0303 if evalin('base','exist(''XYhist'',''var'');'),
0304 XYhist = evalin('base','XYhist');
0305
0306 set = getfield(XYhist,['set',num2str(XYhist.set)]);
0307 if isequal(set.labels,XY.labels),
0308 set.data(end+1,:) = XY.data;
0309 XYhist = setfield(XYhist,['set',num2str(XYhist.set)],set);
0310 assignin('base','XYhist',XYhist);
0311 else
0312 fprintf('\nWarning: creating new set of XYhist in base workspace.\n\n');
0313 XYhist.set = XYhist.set + 1;
0314 XYhist = setfield(XYhist,['set',num2str(XYhist.set)],XY);
0315 assignin('base','XYhist',XYhist);
0316 end
0317 else
0318 XYhist.set = 1;
0319 XYhist.set1 = XY;
0320 assignin('base','XYhist',XYhist);
0321 end
0322
0323 return
0324
0325
0326
0327 function [H] = moveXY(H,move)
0328
0329 interp = get(H.interp,'Value');
0330 xinterp = get(H.xinterp,'Value');
0331
0332 if (xinterp > 0) & (interp > 1),
0333
0334
0335 switch move,
0336 case 'nexty', H.data.yindex = H.data.yindex + 1;
0337 case 'prevy', H.data.yindex = H.data.yindex - 1;
0338 case 'ygt',
0339 ydata = interpYall(H);
0340 [ysort,yi] = sort(ydata);
0341 currYI = find(ysort > H.data.ypoint);
0342 if min(currYI),
0343 H.data.yindex = yi(min(currYI));
0344 end
0345 case 'ylt',
0346 ydata = interpYall(H);
0347 [ysort,yi] = sort(ydata);
0348 currYI = find(ysort < H.data.ypoint);
0349 if max(currYI),
0350 H.data.yindex = yi(max(currYI));
0351 end
0352 case 'nextx',
0353 H.data.xpoint = H.data.xpoint + xinterp;
0354 case 'prevx',
0355 H.data.xpoint = H.data.xpoint - xinterp;
0356 end
0357 H = checkdatarange(H);
0358 H = interpY(H);
0359 updateGUI(H);
0360 return
0361 end
0362
0363
0364
0365
0366 if (interp > 1)
0367 xdata = H.data.xdata(:,H.data.yindex);
0368 [H.data.xindex] = NearestXYArrayPoint( xdata, H.data.xpoint, move );
0369 end
0370
0371 switch move,
0372 case 'nextx',
0373
0374 if(interp == 1), H.data.xindex = H.data.xindex + 1; end
0375 case 'prevx',
0376
0377 if(interp == 1), H.data.xindex = H.data.xindex - 1; end
0378 case 'nexty', H.data.yindex = H.data.yindex + 1;
0379 case 'prevy', H.data.yindex = H.data.yindex - 1;
0380 case 'ygt',
0381 ydata = H.data.ydata(H.data.xindex,:);
0382 [ysort,yi] = sort(ydata);
0383 currYI = find(ysort == H.data.ypoint);
0384 if currYI < length(yi),
0385 H.data.yindex = yi(currYI+1);
0386 end
0387 case 'ylt',
0388 ydata = H.data.ydata(H.data.xindex,:);
0389 [ysort,yi] = sort(ydata);
0390 currYI = find(ysort == H.data.ypoint);
0391 if currYI > 1,
0392 H.data.yindex = yi(currYI-1);
0393 end
0394 otherwise
0395 end
0396
0397 H = checkdatarange(H);
0398
0399
0400 H.data.xpoint = H.data.xdata(H.data.xindex,H.data.yindex);
0401 H.data.ypoint = H.data.ydata(H.data.xindex,H.data.yindex);
0402
0403 set(H.interp,'Value',1);
0404 H = updateGUI(H);
0405
0406 return
0407
0408
0409
0410 function [ H ] = checkdatarange(H),
0411
0412
0413 s = size(H.data.xdata,1);
0414 if( H.data.xindex < 1 ),
0415 H.data.xindex = 1;
0416 elseif( H.data.xindex >= s ),
0417 H.data.xindex = s;
0418 end
0419 s = size(H.data.ydata,2);
0420 if( H.data.yindex < 1 ),
0421 H.data.yindex = 1;
0422 elseif( H.data.yindex >= s ),
0423 H.data.yindex = s;
0424 end
0425
0426 return
0427
0428
0429
0430 function [ H ] = updateDATA( H )
0431
0432
0433
0434 set(H.gui,'units','normalized');
0435 axpos = get(H.axis,'position');
0436 figcp = get(H.gui,'Currentpoint');
0437 axlim = axpos(1) + axpos(3);
0438 aylim = axpos(2) + axpos(4);
0439 if or(figcp(1) > (axlim+.01), figcp(1) < (axpos(1)-.01)),
0440 return;
0441 elseif or(figcp(2) > (aylim+.01), figcp(2) < (axpos(2)-.01)),
0442 return;
0443 end
0444
0445 CurrentPoint = get(H.axis,'Currentpoint');
0446 H.data.xpoint = CurrentPoint(1,1);
0447 H.data.ypoint = CurrentPoint(1,2);
0448
0449 if get(H.traceNearest,'Value'),
0450
0451
0452 [ H.data.xpoint, ...
0453 H.data.xindex, ...
0454 H.data.ypoint, ...
0455 H.data.yindex ] = NearestXYMatrixPoint( H.data.xdata,...
0456 H.data.ydata,...
0457 H.data.xpoint,...
0458 H.data.ypoint);
0459 end
0460
0461 CurrentPoint = get(H.axis,'Currentpoint');
0462 H.data.xpoint = CurrentPoint(1,1);
0463 H.data.ypoint = CurrentPoint(1,2);
0464
0465 H = interpY(H);
0466 H = updateGUI(H);
0467
0468 return
0469
0470
0471 function [ H ] = updateGUI( H )
0472
0473 InterpMethod = get(H.interp,'Value');
0474 if (InterpMethod > 1)
0475
0476
0477
0478
0479 set(H.xindex,'String','interp');
0480 else
0481 set(H.xindex,'String',num2str(H.data.xindex));
0482 end
0483 set(H.xindex,'Value',H.data.xindex);
0484
0485 tracestr = sprintf('%d',H.data.yindex);
0486 set(H.yindex,'String',tracestr,'Value',uint16(H.data.yindex));
0487
0488
0489
0490 x_rng = get(H.axis,'Xlim');
0491 y_rng = get(H.axis,'Ylim');
0492 set(H.data.xline,'Xdata',[H.data.xpoint H.data.xpoint],'Ydata',y_rng);
0493 set(H.data.yline,'Ydata',[H.data.ypoint H.data.ypoint],'Xdata',x_rng);
0494
0495
0496 xstring = sprintf('%g',H.data.xpoint);
0497 ystring = sprintf('%g',H.data.ypoint);
0498 set(H.xvalue,'String',xstring,'Value',H.data.xpoint);
0499 set(H.yvalue,'String',ystring,'Value',H.data.ypoint);
0500
0501
0502 fyeq = get(H.fyeq,'string');
0503 fyval = eval(strrep(fyeq,'y',ystring));
0504 fystr = sprintf('%g',fyval);
0505 set(H.fyvalue,'String',fystr,'Value',fyval);
0506
0507
0508 fxeq = get(H.fxeq,'string');
0509 fxval = eval(strrep(fxeq,'x',xstring));
0510 fxstr = sprintf('%g',fxval);
0511 set(H.fxvalue,'String',fxstr,'Value',fxval);
0512
0513 return
0514
0515
0516 function [ H ] = interpY( H )
0517
0518
0519 xdata = H.data.xdata(:,H.data.yindex);
0520 ydata = H.data.ydata(:,H.data.yindex);
0521
0522 if H.data.xpoint >= max(xdata)
0523 H.data.xpoint = max(xdata);
0524 H.data.xindex = find(xdata == max(xdata));
0525 H.data.ypoint = ydata(H.data.xindex);
0526 return;
0527 elseif H.data.xpoint <= min(xdata)
0528 H.data.xpoint = min(xdata);
0529 H.data.xindex = find(xdata == min(xdata));
0530 H.data.ypoint = ydata(H.data.xindex);
0531 return;
0532 end
0533
0534
0535 interp = get(H.interp,'Value');
0536
0537 switch interp
0538 case 1
0539
0540
0541 [H.data.xindex, H.data.xpoint] = NearestXYArrayPoint( xdata, H.data.xpoint );
0542 H.data.ypoint = ydata(H.data.xindex);
0543 case 2
0544 H.data.ypoint = interp1( xdata, ydata, H.data.xpoint, 'nearest' );
0545 case 3
0546 H.data.ypoint = interp1( xdata, ydata, H.data.xpoint, 'linear' );
0547 case 4
0548 H.data.ypoint = interp1( xdata, ydata, H.data.xpoint, 'spline' );
0549 case 5
0550 H.data.ypoint = interp1( xdata, ydata, H.data.xpoint, 'cubic' );
0551 otherwise
0552
0553 H.data.ypoint = interp1( xdata, ydata, H.data.xpoint );
0554 end
0555
0556 return
0557
0558
0559 function [ Yall ] = interpYall( H )
0560
0561 xdata = H.data.xdata(:,H.data.yindex);
0562 Yall = H.data.ydata;
0563
0564 if H.data.xpoint >= max(xdata),
0565 H.data.xpoint = max(xdata);
0566 H.data.xindex = find(xdata == max(xdata));
0567 Yall = ydata(:,H.data.xindex);
0568 return;
0569 elseif H.data.xpoint <= min(xdata),
0570 H.data.xpoint = min(xdata);
0571 H.data.xindex = find(xdata == min(xdata));
0572 Yall = ydata(:,H.data.xindex);
0573 return;
0574 end
0575
0576
0577 interp = get(H.interp,'Value');
0578
0579 switch interp,
0580 case 1
0581
0582 case 2
0583 Yall = interp1( xdata, Yall, H.data.xpoint, 'nearest' );
0584 case 3
0585 Yall = interp1( xdata, Yall, H.data.xpoint, 'linear' );
0586 case 4
0587 Yall = interp1( xdata, Yall, H.data.xpoint, 'spline' );
0588 case 5
0589 Yall = interp1( xdata, Yall, H.data.xpoint, 'cubic' );
0590 otherwise
0591
0592 Yall = interp1( xdata, Yall, H.data.xpoint );
0593 end
0594
0595 return
0596
0597
0598 function [ index, point ] = NearestXYArrayPoint( data_array, point, type )
0599
0600 if ~exist('type','var') type = ''; end
0601
0602
0603
0604
0605
0606
0607 if point >= max(data_array)
0608 point = max(data_array);
0609 index = find(data_array == point);
0610 return;
0611 elseif point <= min(data_array)
0612 point = min(data_array);
0613 index = find(data_array == point);
0614 return;
0615 end
0616
0617 data_sorted = sort(data_array);
0618
0619 greater = find(data_sorted > point);
0620 greater_index = greater(1);
0621
0622 lesser = find(data_sorted < point);
0623 lesser_index = lesser(length(lesser));
0624
0625 greater_dif = data_sorted(greater_index) - point;
0626 lesser_dif = point - data_sorted(lesser_index);
0627
0628 if strcmp(type,'nextx'),
0629 index = greater_index;
0630 elseif strcmp(type,'prevx'),
0631 index = lesser_index;
0632 else
0633 if (greater_dif < lesser_dif)
0634 index = find(data_array == data_sorted(greater_index));
0635 else
0636 index = find(data_array == data_sorted(lesser_index));
0637 end
0638 end
0639 point = data_array(index);
0640
0641 return
0642
0643
0644
0645 function [ xpoint, xindex, ypoint, yindex ] = NearestXYMatrixPoint( Xdata, Ydata, xpoint, ypoint )
0646
0647
0648
0649
0650
0651
0652
0653
0654 [ xindex, xpoint ] = NearestXYArrayPoint( Xdata(:,1), xpoint );
0655
0656
0657
0658 ydata = Ydata(xindex,:);
0659
0660
0661
0662 [ yindex, ypoint ] = NearestXYArrayPoint( ydata, ypoint );
0663
0664 return
0665
0666
0667
0668 function [ data ] = get_data,
0669
0670
0671
0672
0673 if gca,
0674
0675
0676 data = get(gca,'userdata');
0677
0678 if isfield(data,'lineobj'),
0679 if data.lineobj,
0680 return;
0681 end
0682 end
0683
0684 data.ylim = get(gca,'ylim');
0685
0686
0687 data.lineobj = findobj(gca,'Type','line');
0688
0689 if data.lineobj,
0690
0691 data.lines = length(data.lineobj);
0692 data.xdata = [];
0693 data.ydata = [];
0694 data.xpoint = [];
0695 data.ypoint = [];
0696 data.xindex = 1;
0697 data.yindex = 1;
0698 for i = data.lines:-1:1,
0699
0700
0701 data.xdata(:,i) = get(data.lineobj(i),'XData').';
0702 data.ydata(:,i) = get(data.lineobj(i),'YData').';
0703 end
0704
0705
0706
0707
0708
0709 x_rng = get(gca,'Xlim');
0710 y_rng = get(gca,'Ylim');
0711 data.xline = line(x_rng,[y_rng(1) y_rng(1)]);
0712 data.yline = line(x_rng,[y_rng(1) y_rng(1)]);
0713 set(data.xline,'Color','r','EraseMode','xor','tag','XHR_XLINE');
0714 set(data.yline,'Color','r','EraseMode','xor','tag','XHR_YLINE');
0715
0716 set(gca,'userdata',data);
0717
0718 else
0719 fprintf('No lines in current axes\n');
0720 end
0721
0722 end
0723
0724 return
0725
0726
0727 function [H] = INIT
0728
0729 H.gui = gcf;
0730 H.axis = gca;
0731
0732 H.data = get_data;
0733
0734
0735 H.button = get(H.gui,'WindowButtonDownFcn');
0736
0737 set(H.gui,'WindowButtonDownFcn','crosshair_subplots(''down'');');
0738 set(H.gui,'KeyPressFcn','crosshair_subplots(''keypress'');');
0739
0740
0741 bgcolor = get(H.gui,'Color');
0742
0743 black = find(bgcolor <= .6);
0744 fgcolor = [0 0 0];
0745 if length(black)>2, fgcolor = [1 1 1]; end
0746
0747
0748 Font.FontName = 'Helvetica';
0749 Font.FontUnits = 'Pixels';
0750 Font.FontSize = 10;
0751 Font.FontWeight = 'normal';
0752 Font.FontAngle = 'normal';
0753
0754
0755 if findobj(gcf,'tag','XHR_YFLIP'),
0756 H.yflip = findobj(gcf,'tag','XHR_YFLIP');
0757 else
0758 H.yflip = uicontrol(H.gui,'tag','XHR_YFLIP','Style','pushbutton',...
0759 'Units','Normalized',Font,...
0760 'Position',[.00 .95 .08 .05],...
0761 'TooltipString','Flip Y Axis', ...
0762 'String','Flip',...
0763 'Callback',strcat('XHR = get(gcf,''userdata'');',...
0764 'ydir = get(XHR.axis,''YDir'');',...
0765 'if isequal(ydir,''normal''),',...
0766 ' set(XHR.axis,''YDir'',''reverse'');',...
0767 'else,',...
0768 ' set(XHR.axis,''YDir'',''normal'');',...
0769 'end;',...
0770 'set(XHR.gui,''userdata'',XHR); figure(XHR.gui); clear XHR;'));
0771 end
0772
0773 if findobj(gcf,'tag','XHR_YRESET'),
0774 H.yreset = findobj(gcf,'tag','XHR_YRESET');
0775 else
0776 H.yreset = uicontrol(H.gui,'tag','XHR_YRESET','Style','pushbutton',...
0777 'Units','Normalized',Font,...
0778 'Position',[.00 .90 .08 .05],...
0779 'TooltipString','Reset Axis Limits', ...
0780 'String','Reset',...
0781 'Callback',strcat('XHR = get(gcf,''userdata'');',...
0782 'XHR.data.ylim = get(XHR.axis,''ylim'');',...
0783 'set(XHR.ymin,''string'',sprintf(''%g'',XHR.data.ylim(1)));',...
0784 'set(XHR.ymax,''string'',sprintf(''%g'',XHR.data.ylim(2)));',...
0785 'set(XHR.gui,''userdata'',XHR); figure(XHR.gui); clear XHR;'));
0786 end
0787
0788 if findobj(gcf,'tag','XHR_YMIN'),
0789 H.ymin = findobj(gcf,'tag','XHR_YMIN');
0790 else
0791 H.ymin = uicontrol(H.gui,'tag','XHR_YMIN','Style','edit',...
0792 'Units','Normalized',Font,...
0793 'Position',[.00 .85 .08 .05],...
0794 'HorizontalAlign','left',...
0795 'TooltipString','Set Y min', ...
0796 'String',sprintf('%g',H.data.ylim(1)),...
0797 'Callback',strcat('XHR = get(gcf,''userdata'');',...
0798 'ymin = str2num(get(XHR.ymin,''string''));',...
0799 'XHR.data.ylim(1) = ymin;',...
0800 'set(XHR.axis,''ylim'',XHR.data.ylim);',...
0801 'set(XHR.ymin,''string'',sprintf(''%g'',XHR.data.ylim(1)));',...
0802 'set(XHR.gui,''userdata'',XHR); figure(XHR.gui); clear XHR ymin;'));
0803 end
0804
0805 if findobj(gcf,'tag','XHR_YMAX'),
0806 H.ymax = findobj(gcf,'tag','XHR_YMAX');
0807 else
0808 H.ymax = uicontrol(H.gui,'tag','XHR_YMAX','Style','edit',...
0809 'Units','Normalized',Font,...
0810 'Position',[.00 .80 .08 .05],...
0811 'HorizontalAlign','left',...
0812 'TooltipString','Set Y max', ...
0813 'String',sprintf('%g',H.data.ylim(2)),...
0814 'Callback',strcat('XHR = get(gcf,''userdata'');',...
0815 'ymax = str2num(get(XHR.ymax,''string''));',...
0816 'XHR.data.ylim(2) = ymax;',...
0817 'set(XHR.axis,''ylim'',XHR.data.ylim);',...
0818 'set(XHR.ymax,''string'',sprintf(''%g'',XHR.data.ylim(2)));',...
0819 'set(XHR.gui,''userdata'',XHR); figure(XHR.gui); clear XHR ymax;'));
0820 end
0821
0822 if findobj(gcf,'tag','XHR_GRID'),
0823 H.grid = findobj(gcf,'tag','XHR_GRID');
0824 else
0825 H.grid = uicontrol(H.gui,'tag','XHR_GRID','Style','checkbox',...
0826 'Units','Normalized',Font,...
0827 'Position',[.00 .75 .08 .05],...
0828 'BackgroundColor',bgcolor,'ForegroundColor',fgcolor,...
0829 'TooltipString','Toggle plot grid on/off.', ...
0830 'String','grid',...
0831 'Callback',strcat('XHR = get(gcf,''userdata'');',...
0832 'grid(XHR.axis);',...
0833 'set(XHR.gui,''userdata'',XHR); figure(XHR.gui); clear XHR;'));
0834 end
0835
0836 if findobj(gcf,'tag','XHR_XVALUE'),
0837 H.xvalue = findobj(gcf,'tag','XHR_XVALUE');
0838 else
0839 H.xvalue = uicontrol(H.gui,'tag','XHR_XVALUE','Style','edit',...
0840 'Units','Normalized',Font,...
0841 'Position',[.13 .95 .15 .05],...
0842 'BackGroundColor',[ 0 .9 0],'ForeGroundColor',[ 0 0 0],...
0843 'TooltipString','X value (Read Only)',...
0844 'String',' ');
0845 end
0846
0847 if findobj(gcf,'tag','XHR_YVALUE'),
0848 H.yvalue = findobj(gcf,'tag','XHR_YVALUE');
0849 else
0850 H.yvalue = uicontrol(H.gui,'tag','XHR_YVALUE','Style','edit',...
0851 'Units','Normalized',Font,...
0852 'Position',[.28 .95 .15 .05],...
0853 'BackGroundColor',[ 0 0 .9],'ForeGroundColor',[ 1 1 1],...
0854 'TooltipString','Y value (Read Only)',...
0855 'String',' ');
0856 end
0857
0858 if findobj(gcf,'tag','XHR_FXEQ'),
0859 H.fxeq = findobj(gcf,'tag','XHR_FXEQ');
0860 else
0861 H.fxeq = uicontrol(H.gui,'tag','XHR_FXEQ','Style','edit',...
0862 'Units','Normalized',...
0863 'Position',[.45 .95 .10 .05],...
0864 'TooltipString','Define f(x) equation here',...
0865 'BackGroundColor',[ 0 .9 0],...
0866 'ForeGroundColor',[ 0 0 0],'String','x');
0867 end
0868
0869 if findobj(gcf,'tag','XHR_FXVALUE'),
0870 H.fxvalue = findobj(gcf,'tag','XHR_FXVALUE');
0871 else
0872 H.fxvalue = uicontrol(H.gui,'tag','XHR_FXVALUE','Style','edit',...
0873 'Units','Normalized',...
0874 'Position',[.55 .95 .15 .05],...
0875 'TooltipString','f(x) result',...
0876 'BackGroundColor',[ 0 .9 0],...
0877 'ForeGroundColor',[ 0 0 0],'String',' ');
0878 end
0879
0880 if findobj(gcf,'tag','XHR_FYEQ'),
0881 H.fyeq = findobj(gcf,'tag','XHR_FYEQ');
0882 else
0883 H.fyeq = uicontrol(H.gui,'tag','XHR_FYEQ','Style','edit',...
0884 'Units','Normalized',...
0885 'Position',[.70 .95 .10 .05],...
0886 'TooltipString','Define f(y) equation here',...
0887 'BackGroundColor',[ 0 0 .9],...
0888 'ForeGroundColor',[ 1 1 1],'String','y');
0889 end
0890
0891 if findobj(gcf,'tag','XHR_FYVALUE'),
0892 H.fyvalue = findobj(gcf,'tag','XHR_FYVALUE');
0893 else
0894 H.fyvalue = uicontrol(H.gui,'tag','XHR_FYVALUE','Style','edit',...
0895 'Units','Normalized',...
0896 'Position',[.80 .95 .15 .05],...
0897 'TooltipString','f(y) result',...
0898 'BackGroundColor',[ 0 0 .9],...
0899 'ForeGroundColor',[ 1 1 1],'String',' ');
0900 end
0901
0902 if findobj(gcf,'tag','XHR_YINDEX'),
0903 H.yindex = findobj(gcf,'tag','XHR_YINDEX');
0904 else
0905 H.yindex = uicontrol(H.gui,'tag','XHR_YINDEX','Style','edit',...
0906 'Units','Normalized',Font,...
0907 'Position',[.92 .87 .08 .05],...
0908 'BackGroundColor',[ 0 0 .9],'ForeGroundColor',[ 1 1 1],...
0909 'TooltipString','Enter Y index into plot data matrix. Same as trace number.',...
0910 'String','1','Value',1,...
0911 'Callback',strcat('XHR = get(gcf,''userdata'');',...
0912 'yi = str2num(get(XHR.yindex,''String''));',...
0913 'XHR.data.yindex = yi;',...
0914 'set(XHR.gui,''userdata'',XHR); clear XHR yi; ',...
0915 '[Xpoint,Ypoint] = crosshair_subplots(''changey'');'));
0916 end
0917
0918 if findobj(gcf,'tag','XHR_YPREV'),
0919 H.yprev = findobj(gcf,'tag','XHR_YPREV');
0920 else
0921 H.yprev = uicontrol(H.gui,'tag','XHR_YPREV','Style','Push',...
0922 'Units','Normalized',Font,...
0923 'Position',[.92 .82 .04 .05],...
0924 'String','<',...
0925 'TooltipString','Goto Previous Y Index (channel).',...
0926 'CallBack','[Xpoint,Ypoint] = crosshair_subplots(''prevy'');');
0927 end
0928
0929 if findobj(gcf,'tag','XHR_YNEXT'),
0930 H.ynext = findobj(gcf,'tag','XHR_YNEXT');
0931 else
0932 H.ynext = uicontrol(H.gui,'tag','XHR_YNEXT','Style','Push',...
0933 'Units','Normalized',Font,...
0934 'Position',[.96 .82 .04 .05],...
0935 'String','>',...
0936 'TooltipString','Goto Next Y Index (channel).',...
0937 'CallBack','[Xpoint,Ypoint] = crosshair_subplots(''nexty'');');
0938 end
0939
0940 if findobj(gcf,'tag','XHR_YLT'),
0941 H.yLT = findobj(gcf,'tag','XHR_YLT');
0942 else
0943 H.yLT = uicontrol(H.gui,'tag','XHR_YLT','Style','Push',...
0944 'Units','Normalized',Font,...
0945 'Position',[.92 .77 .04 .05],...
0946 'String','LT',...
0947 'TooltipString','Goto next Y Less Than current Y.',...
0948 'CallBack','[Xpoint,Ypoint] = crosshair_subplots(''yLT'');');
0949 end
0950
0951 if findobj(gcf,'tag','XHR_YGT'),
0952 H.yGT = findobj(gcf,'tag','XHR_YGT');
0953 else
0954 H.yGT = uicontrol(H.gui,'tag','XHR_YGT','Style','Push',...
0955 'Units','Normalized',Font,...
0956 'Position',[.96 .77 .04 .05],...
0957 'String','GT',...
0958 'TooltipString','Goto next Y Greater Than current Y.',...
0959 'CallBack','[Xpoint,Ypoint] = crosshair_subplots(''yGT'');');
0960 end
0961
0962 if findobj(gcf,'tag','XHR_XINDEX'),
0963 H.xindex = findobj(gcf,'tag','XHR_XINDEX');
0964 else
0965 H.xindex = uicontrol(H.gui,'tag','XHR_XINDEX','Style','edit',...
0966 'Units','Normalized',Font,...
0967 'Position',[.92 .70 .08 .05],...
0968 'BackGroundColor',[ 0 .9 0],'ForeGroundColor',[ 0 0 0],...
0969 'TooltipString','Enter X index into plot data matrix. Only available for interpolation = ''none''.',...
0970 'String','1','Value',1,...
0971 'Callback',strcat('XHR = get(gcf,''userdata'');',...
0972 'xi = str2num(get(XHR.xindex,''String''));',...
0973 'XHR.data.xindex = xi;',...
0974 'set(XHR.xinterp,''value'',0); ',...
0975 'set(XHR.xinterp,''string'',''0''); ',...
0976 'set(XHR.interp, ''value'',1); ',...
0977 'set(XHR.gui,''userdata'',XHR); clear XHR; ',...
0978 '[Xpoint,Ypoint] = crosshair_subplots(''changex'');'));
0979 end
0980
0981 if findobj(gcf,'tag','XHR_XPREV'),
0982 H.xprev = findobj(gcf,'tag','XHR_XPREV');
0983 else
0984 H.xprev = uicontrol(H.gui,'tag','XHR_XPREV','Style','Push',...
0985 'Units','Normalized',Font,...
0986 'Position',[.92 .65 .04 .05],...
0987 'String','<',...
0988 'TooltipString','Goto Previous X Index (no interpolation).',...
0989 'CallBack','[Xpoint,Ypoint] = crosshair_subplots(''prevx'');');
0990 end
0991
0992 if findobj(gcf,'tag','XHR_XNEXT'),
0993 H.xnext = findobj(gcf,'tag','XHR_XNEXT');
0994 else
0995 H.xnext = uicontrol(H.gui,'tag','XHR_XNEXT','Style','Push',...
0996 'Units','Normalized',Font,...
0997 'Position',[.96 .65 .04 .05],...
0998 'String','>',...
0999 'TooltipString','Goto Next X Index (no interpolation).',...
1000 'CallBack','[Xpoint,Ypoint] = crosshair_subplots(''nextx'');');
1001 end
1002
1003 if findobj(gcf,'tag','XHR_XINTERP'),
1004 H.xinterp = findobj(gcf,'tag','XHR_XINTERP');
1005 else
1006 H.xinterp = uicontrol(H.gui,'tag','XHR_XINTERP','Style','Edit',...
1007 'Units','Normalized',...
1008 'Position',[.92 .60 .08 .05],...
1009 'String','0','Value',0,...
1010 'TooltipString','Interpolation X increment (zero = nearest X).',...
1011 'Callback',strcat('XHR = get(gcf,''userdata''); ',...
1012 'xint = str2num(get(XHR.xinterp,''string'')); ',...
1013 'set(XHR.xinterp,''value'',xint); ',...
1014 'set(XHR.gui,''userdata'',XHR); figure(XHR.gui); clear XHR; '));
1015 end
1016
1017 if findobj(gcf,'tag','XHR_INTERP'),
1018 H.interp = findobj(gcf,'tag','XHR_INTERP');
1019 else
1020 interpstr = 'none|nearest|linear|spline|cubic';
1021 H.interp = uicontrol(H.gui,'tag','XHR_INTERP','Style','popup',...
1022 'Units','Normalized',Font,...
1023 'Position',[.92 .55 .08 .05],...
1024 'TooltipString','INTERP1 methods (none = raw values).', ...
1025 'String',interpstr,...
1026 'Callback',strcat('XHR = get(gcf,''userdata'');',...
1027 'xint = get(XHR.xinterp,''Value''); ',...
1028 'if xint == 0, ',...
1029 ' xint = 0.5; ',...
1030 ' set(XHR.xinterp,''value'',xint); ',...
1031 ' set(XHR.xinterp,''string'',num2str(xint)); ',...
1032 ' set(XHR.xindex, ''string'',''interp''); ',...
1033 'end; ',...
1034 'set(XHR.gui,''userdata'',XHR); figure(XHR.gui); clear XHR; '));
1035 end
1036
1037 if findobj(gcf,'tag','XHR_STORE'),
1038 H.store = findobj(gcf,'tag','XHR_STORE');
1039 else
1040 H.store = uicontrol(H.gui,'tag','XHR_STORE','Style','Push',...
1041 'Units','Normalized',...
1042 'Position',[.92 .40 .08 .05],...
1043 'String','Store',...
1044 'TooltipString','Store current Channel & XY values into base XYhist array.', ...
1045 'CallBack','crosshair_subplots(''store'');');
1046 end
1047
1048 if findobj(gcf,'tag','XHR_DONE'),
1049 H.done = findobj(gcf,'tag','XHR_DONE');
1050 else
1051 H.done = uicontrol(H.gui,'tag','XHR_DONE','Style','Push',...
1052 'Units','Normalized',...
1053 'Position',[.80 .00 .10 .05],...
1054 'BackgroundColor',[.8 .5 0],...
1055 'ForegroundColor',[1 1 1],...
1056 'FontWeight','bold',...
1057 'String','Done',...
1058 'TooltipString','Close crosshair', ...
1059 'CallBack','crosshair_subplots(''done'');');
1060 end
1061
1062 if findobj(gcf,'tag','XHR_EXIT'),
1063 H.exit = findobj(gcf,'tag','XHR_EXIT');
1064 else
1065 H.exit = uicontrol(H.gui,'tag','XHR_EXIT','Style','Push',...
1066 'Units','Normalized',...
1067 'Position',[.90 .00 .10 .05],...
1068 'BackgroundColor',[.8 0 0],...
1069 'ForegroundColor',[1 1 1],...
1070 'FontWeight','bold',...
1071 'String','Exit',...
1072 'TooltipString','Close crosshair and Figure', ...
1073 'CallBack','crosshair_subplots(''exit'');');
1074 end
1075
1076 if findobj(gcf,'tag','XHR_TRACENEAREST'),
1077 H.traceNearest = findobj(gcf,'tag','XHR_TRACENEAREST');
1078 else
1079 H.traceNearest = uicontrol(H.gui,'tag','XHR_TRACENEAREST','Style','checkbox',...
1080 'Units','Normalized',...
1081 'Position',[.60 .00 .19 .05],...
1082 'BackgroundColor',bgcolor,'ForegroundColor',fgcolor,...
1083 'String','Nearest Trace','Value',1,...
1084 'TooltipString','Trace nearest to mouse click; switch off to keep trace constant.');
1085 end
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125 set(H.axis,'userdata',H.data);
1126 set(H.gui,'userdata',H);
1127
1128 return