IDENTIFY Identify points on a plot by clicking with the mouse. CALL: v = identify(x,y,sym,text); v = indices to the identified points. x,y = data plotted sym = plot symbol for x and y. (default '*') text = a character array or cell array of text strings to annotate the identified points. This routine plots x versus y and waits for mouse clicks to identify points. Click with left button on points and end with middle button or space bar. Plotsymbol and text strings are optional input arguments. Examples: x = rand(50,1);y=rand(50,1); v = identify(x,y) % click on 2 points
Covariance matrix. | |
Display message and abort function. | |
Graphical input from mouse. | |
Hold current graph. | |
True for cell array. | |
True for character array (string). | |
Linear plot. | |
Write formatted data to string. | |
Text annotation. |
001 function v = identify(x,y,arg3,arg4) 002 %IDENTIFY Identify points on a plot by clicking with the mouse. 003 % 004 % CALL: v = identify(x,y,sym,text); 005 % 006 % v = indices to the identified points. 007 % x,y = data plotted 008 % sym = plot symbol for x and y. (default '*') 009 % text = a character array or cell array of text strings to annotate 010 % the identified points. 011 % 012 % This routine plots x versus y and waits for mouse clicks 013 % to identify points. Click with left button on points and 014 % end with middle button or space bar. Plotsymbol and text 015 % strings are optional input arguments. 016 % 017 % Examples: 018 % x = rand(50,1);y=rand(50,1); 019 % v = identify(x,y) % click on 2 points 020 021 022 % Second example doesn't work 023 % v2 = identify(x(v),y(v),'r.',{'test','test2'}) % look closer on them 024 025 026 % Tested on Matlab 5.x 027 % History: 028 % revised pab: updated help header 029 % GPL Copyright (c) Anders Holtsberg, 1998 030 031 plotsymbol = '*'; 032 textvector = 1:length(x); 033 for i = 3:nargin 034 if i == 3 035 A = arg3; 036 else 037 A = arg4; 038 end 039 if max(size(A)) <= 1 040 plotsymbol = A; 041 elseif size(A,1) == length(x) | ... 042 (size(A,1) == 1 & size(A,2) == length(x)) | iscell(A) 043 if min(size(A)) == 1 044 A = A(:); 045 end 046 textvector = A; 047 else 048 error('Argument incompatibility') 049 end 050 end 051 052 if ~isempty(plotsymbol), plot(x,y,plotsymbol); end 053 cx = cov(x); 054 cy = cov(y); 055 v = []; 056 B = 1; 057 while B == 1 058 [xc,yc,B] = ginput(1); 059 if B == 1 060 d = (x-xc).^2/cx+(y-yc).^2/cy; 061 [d i] = sort(d); 062 i = i(1); 063 v = [v; i]; 064 hold on 065 if ischar(textvector) 066 text(xc,yc,textvector(i,:)); 067 elseif iscell(textvector) 068 text(xc,yc,textvector{i}); 069 else 070 text(xc,yc,sprintf(' %g',textvector(i))); 071 end 072 end 073 end 074 hold off 075
Comments or corrections to the WAFO group