声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

声振论坛 展示 基础理论 查看内容

两个现有的fig图画在一起比较

2012-12-3 10:08| 发布者: aspen| 查看: 3765| 评论: 0|原作者: ChaChing|来自: 振动论坛

摘要: 本想直接回覆http://www.chinavib.com/forum/thread-83796-1-1.html, 但不确定是否对题! 且不太会搜索的我, 想想个人日後找寻方便, 就直接发帖! 这是几年前, 处理一堆试验资料时, 为方便比较不同案件间的差异, 应急 ...
这个以前上传过, http://www.chinavib.com/thread-72970-1-1.html
今天被翻上来, 但有更新过, 感觉摆在这裡一起比较好







  1. function varargout = PickAxes(varargin)
  2. % PickAxes    - Pick one axes handle from figure. (91.11.06, JCK)
  3. %
  4. % [hAxes,xData,yData,button,cData] = PickAxes(hFig)
  5. %
  6. %      hFig : figure handle (default : gcf)
  7. %     hAxes : picked axes handle from hFig figure
  8. %     xData : x coordinate of line in axes which select by mouse
  9. %     yData : y coordinate of line in axes which select by mouse
  10. %     cData : image data in axes which select by mouse
  11. %    button : mouse button id
  12. %
  13. %    *** input/output is optinal select. if no output argument, pick axes only.
  14. %    *** xData/yData may be more column if the selected axes have more lines.
  15. %
  16. %    See also LOOPHP, STRIPPLOT, ORBITPLOT.

  17. %  92.03.29 - include comment and I/O check & modify some logic.
  18. %  92.08.19 - modify the logic for using beep to match V6.5.
  19. %  92.12.16 - add legend check & change 'axes' to 'set' type & reverse x/y data.
  20. %  96.09.26 - modify for different point line case.

  21. % Ckeck the input & output property
  22.   PreS = [blanks(10),'*** Error : ']; EndS = ' !  <== PickAxes ***';
  23.   PreW = [blanks(5),'*** '];
  24.   if nargin > 1, error([PreS,'No more 1 input arguments',EndS]); end
  25.   if nargout > 5, error([PreS,'No more 5 output arguments',EndS]); end

  26.   hFig = gcf;  % default - current figure
  27.   if nargin >= 1, hFig = varargin{1}; if isempty(hFig), hFig = gcf; end
  28.      if ~strcmp( get(hFig,'Type'), 'figure')
  29.         error([PreS,'Input argument is not figure handle',EndS]); end
  30.   end

  31. % *** Begin the picking process ***

  32.   figure(hFig); PsF = get(gcf,'Position'); hAxes = []; xData = []; yData = []; cData = [];
  33.   set(0,'PointerLocation',[PsF(1)+PsF(3)/2,PsF(2)+PsF(4)/2]); [xp,yp,button] = ginput(1);
  34.   if isempty(button), button = 99; end  % Keyboard Enter
  35.   if button == 2, pause; end  % Selection for pause
  36.   if button == 1 | button == 3, CpF = get(gcf,'CurrentPoint');
  37.      PosX=CpF(1)/PsF(3); PosY=CpF(2)/PsF(4); hAxesK = get(hFig,'Children');
  38.      for K = 1:length(hAxesK)
  39.      if strcmp(get(hAxesK(K),'Type'),'axes') & ~strcmp(get(hAxesK(K),'Tag'),'legend')
  40.          hKPos = get(hAxesK(K),'Position');
  41.          hKPos(3) = hKPos(1) + hKPos(3); hKPos(4) = hKPos(2) + hKPos(4);

  42.          if hKPos(1)<=PosX & PosX<=hKPos(3) & hKPos(2)<=PosY & PosY<=hKPos(4)
  43.             hAxes = hAxesK(K); set(hFig,'CurrentAxes',hAxes); % axes(hFig);
  44.             hLineK = get(hAxes,'Children'); break; end
  45.      end; end
  46.      if nargout >= 2, if ~isempty(hAxes) & ~isempty(hLineK)
  47.         for K=length(hLineK):-1:1
  48.            if strcmp(get(hLineK(K),'Type'),'line')
  49.               xp = get(hLineK(K),'XData'); yp = get(hLineK(K),'YData');
  50.               try, xData = [xData, xp']; yData = [yData, yp'];  % 96.09.26
  51.               catch, xData = [xData; xp']; yData = [yData; yp']; end
  52.            end
  53.            if strcmp(get(hLineK(K),'Type'),'image')  % 97.11.20
  54.               xData = get(hLineK(K),'XData'); yData = get(hLineK(K),'YData');
  55.               cData = get(hLineK(K),'CData');
  56.            end
  57.         end
  58.      end; end
  59.   end

  60. % output arguments definition
  61.   if nargout >= 1, varargout{1} = hAxes; if nargout >= 2, varargout{2} = xData;
  62.      if nargout >= 3, varargout{3} = yData; if nargout >= 4, varargout{4} = button;
  63.          if nargout >= 5, varargout{5} = cData; end
  64.   end; end; end; end
  65.   return
复制代码

本文内容由 ChaChing 提供

123

最新评论

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-28 14:43 , Processed in 0.037936 second(s), 15 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部