这个以前上传过, http://www.chinavib.com/thread-72970-1-1.html
今天被翻上来, 但有更新过, 感觉摆在这裡一起比较好
- function varargout = PickAxes(varargin)
- % PickAxes - Pick one axes handle from figure. (91.11.06, JCK)
- %
- % [hAxes,xData,yData,button,cData] = PickAxes(hFig)
- %
- % hFig : figure handle (default : gcf)
- % hAxes : picked axes handle from hFig figure
- % xData : x coordinate of line in axes which select by mouse
- % yData : y coordinate of line in axes which select by mouse
- % cData : image data in axes which select by mouse
- % button : mouse button id
- %
- % *** input/output is optinal select. if no output argument, pick axes only.
- % *** xData/yData may be more column if the selected axes have more lines.
- %
- % See also LOOPHP, STRIPPLOT, ORBITPLOT.
- % 92.03.29 - include comment and I/O check & modify some logic.
- % 92.08.19 - modify the logic for using beep to match V6.5.
- % 92.12.16 - add legend check & change 'axes' to 'set' type & reverse x/y data.
- % 96.09.26 - modify for different point line case.
- % Ckeck the input & output property
- PreS = [blanks(10),'*** Error : ']; EndS = ' ! <== PickAxes ***';
- PreW = [blanks(5),'*** '];
- if nargin > 1, error([PreS,'No more 1 input arguments',EndS]); end
- if nargout > 5, error([PreS,'No more 5 output arguments',EndS]); end
- hFig = gcf; % default - current figure
- if nargin >= 1, hFig = varargin{1}; if isempty(hFig), hFig = gcf; end
- if ~strcmp( get(hFig,'Type'), 'figure')
- error([PreS,'Input argument is not figure handle',EndS]); end
- end
- % *** Begin the picking process ***
- figure(hFig); PsF = get(gcf,'Position'); hAxes = []; xData = []; yData = []; cData = [];
- set(0,'PointerLocation',[PsF(1)+PsF(3)/2,PsF(2)+PsF(4)/2]); [xp,yp,button] = ginput(1);
- if isempty(button), button = 99; end % Keyboard Enter
- if button == 2, pause; end % Selection for pause
- if button == 1 | button == 3, CpF = get(gcf,'CurrentPoint');
- PosX=CpF(1)/PsF(3); PosY=CpF(2)/PsF(4); hAxesK = get(hFig,'Children');
- for K = 1:length(hAxesK)
- if strcmp(get(hAxesK(K),'Type'),'axes') & ~strcmp(get(hAxesK(K),'Tag'),'legend')
- hKPos = get(hAxesK(K),'Position');
- hKPos(3) = hKPos(1) + hKPos(3); hKPos(4) = hKPos(2) + hKPos(4);
- if hKPos(1)<=PosX & PosX<=hKPos(3) & hKPos(2)<=PosY & PosY<=hKPos(4)
- hAxes = hAxesK(K); set(hFig,'CurrentAxes',hAxes); % axes(hFig);
- hLineK = get(hAxes,'Children'); break; end
- end; end
- if nargout >= 2, if ~isempty(hAxes) & ~isempty(hLineK)
- for K=length(hLineK):-1:1
- if strcmp(get(hLineK(K),'Type'),'line')
- xp = get(hLineK(K),'XData'); yp = get(hLineK(K),'YData');
- try, xData = [xData, xp']; yData = [yData, yp']; % 96.09.26
- catch, xData = [xData; xp']; yData = [yData; yp']; end
- end
- if strcmp(get(hLineK(K),'Type'),'image') % 97.11.20
- xData = get(hLineK(K),'XData'); yData = get(hLineK(K),'YData');
- cData = get(hLineK(K),'CData');
- end
- end
- end; end
- end
- % output arguments definition
- if nargout >= 1, varargout{1} = hAxes; if nargout >= 2, varargout{2} = xData;
- if nargout >= 3, varargout{3} = yData; if nargout >= 4, varargout{4} = button;
- if nargout >= 5, varargout{5} = cData; end
- end; end; end; end
- return
复制代码 本文内容由 ChaChing 提供 |