声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

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

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

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

摘要: 本想直接回覆http://www.chinavib.com/forum/thread-83796-1-1.html, 但不确定是否对题! 且不太会搜索的我, 想想个人日後找寻方便, 就直接发帖! 这是几年前, 处理一堆试验资料时, 为方便比较不同案件间的差异, 应急 ...
本想直接回覆http://www.chinavib.com/forum/thread-83796-1-1.html, 但不确定是否对题! 且不太会搜索的我, 想想个人日後找寻方便, 就直接发帖!
这是几年前, 处理一堆试验资料时, 为方便比较不同案件间的差异, 应急临时写的!
基本上, 两图都可各有多条线! 若有错误亦请告知!




  1. function varargout = Comp2Fig(varargin)
  2. % Comp2Fig - Combine 2 figure for comparison.
  3. %
  4. % Comp2Fig or Comp2Fig(hFig1,hFig2)
  5. %
  6. % hFig1 : input figure handle for base (empty for user selection)
  7. % hFig2 : input figure handle for other (empty for user selection)
  8. % *** No output arguments, input is optinal select
  9. %

  10. % Ckeck the input & output property
  11. PreS = [blanks(10),'*** Error : ']; EndS = ' ! <== Comp2Fig ***'; PreW = [blanks(5),'*** '];
  12. if nargin > 2, error([PreS,'No more 3 input arguments',EndS]); end
  13. if nargout > 0, error([PreS,'No any output arguments',EndS]); end

  14. hFig1 = []; hFig2 = []; DefName = '';
  15. if nargin >= 1, hFig1 = varargin{1}; if nargin >= 2, hFig2 = varargin{2}; end; end

  16. % Begin the figure comparison process
  17. % read the base figure
  18. if isempty(hFig1)
  19.    TitleS = 'Choise the base file for figure combining (Cancel to Quit from Comp2Fig) :';
  20.    beep; [FileName1,PathName] = uigetfile('*.fig',TitleS);
  21.    if FileName1==0, beep; disp([PreW,'File not ready ?',EndS]); return; % abort action
  22.    else cd(PathName); end % change directory
  23.    try, open(FileName1); hFig1 = gcf; catch, return; end;
  24.    DefName = FileName1;
  25. end; hAxes1=get(hFig1,'Children'); pause(0.5);

  26. % read the another figure
  27. if isempty(hFig2)
  28.    TitleS = 'Choise the other file for figure combining (Cancel to Quit from Comp2Fig) :';
  29.    beep; [FileName2,PathName] = uigetfile('*.fig',TitleS);
  30.    if FileName2==0, beep; disp([PreW,'File not ready ?',EndS]); return; % abort action
  31.    else cd(PathName); end % change directory
  32.    try, open(FileName2); hFig2 = gcf; catch, return; end
  33. end; hAxes2=get(hFig2,'Children');

  34. % compare 2 figure
  35. for m = 1:length(hAxes2)
  36.    LColor=get(hAxes1(m),'ColorOrder'); iLine=0;
  37.    hLine1 = get(hAxes1(m),'Children');
  38.    for K=length(hLine1):-1:1, if get(hLine1(K),'Type')=='line', iLine=iLine+1; end; end
  39.    hLine2 = get(hAxes2(m),'Children');
  40.    for K=length(hLine2):-1:1, if get(hLine2(K),'Type')=='line'
  41.       xp = get(hLine2(K),'XData'); yp = get(hLine2(K),'YData'); iLine=iLine+1;
  42.       figure(hFig1); set(hFig1,'CurrentAxes',hAxes1(m)); grid on; hold on;
  43.       hhn=plot(xp,yp); set(hhn,'Color',LColor(mod(iLine,7)+1,:)); axis auto;
  44.    end; end
  45.    xlabel( get( get(hAxes2(m),'XLabel'), 'String') );
  46.    ylabel( get( get(hAxes2(m),'YLabel'), 'String') );
  47. end

  48. % save the combine figure
  49. pause(0.5);
  50. TitleS = 'Filename for saveing plot (Cancel to not save) :';
  51. beep; [FileName3,PathName3] = uiputfile(DefName,TitleS);
  52. if FileName3==0, FileName3=[]; end % abort the save file action
  53. if ~isempty(FileName3),
  54.    try, saveas(hFig1,[PathName3,FileName3]);
  55.    catch, saveas(hFig1,[PathName3,strtok(FileName3,'.')],'fig'); end
  56. end
  57. close(hFig2);

  58. % no output arguments definition
  59. beep; disp([PreW,'Function is complete',EndS]);
  60. return
复制代码

[ 本帖最后由 ChaChing 于 2009-6-28 20:26 编辑 ]
123下一页

最新评论

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

GMT+8, 2024-11-28 12:05 , Processed in 0.044386 second(s), 15 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部