twodcomp.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. function ax=twodcomp(A,B,varargin)
  2. plot_type='surf';
  3. plot_ax='v';
  4. ax_h=0.2;
  5. ax_w=0.2;
  6. ax_h_off=0.1;
  7. ax_w_off=0.1;
  8. x=1:size(A,2);
  9. y=1:size(A,1);
  10. fig=[];
  11. gap=0.05;
  12. cmin=min([A(:);B(:);B(:)-A(:)]);
  13. cmax=max([A(:);B(:);B(:)-A(:)]);
  14. ax=[];
  15. plot_colorbar=false;
  16. utils.overridedefaults(who,varargin)
  17. if isempty(fig)
  18. fig=figure;
  19. end
  20. if isempty(ax)
  21. ax=make_axes(plot_ax,ax_w,ax_h,gap,ax_w_off,ax_h_off);
  22. end
  23. switch plot_type,
  24. case 'img'
  25. imagesc(x,y,A,'parent',ax(3));
  26. imagesc(x,y,B,'parent',ax(2)); %colorbar('peer',ax(2));
  27. imagesc(x,y,B-A,'parent',ax(1));%colorbar('peer',ax(3));
  28. set(ax,'CLim',[cmin,cmax]);
  29. axis(ax,'xy');
  30. if plot_colorbar
  31. pos=get(ax(3),'Position');
  32. colorbar('peer',ax(3),'Position',[pos(1)+pos(3)+0.01 pos(2) 0.03 pos(4)]);
  33. end
  34. case 'surf'
  35. surf(ax(3),x,y,A);
  36. surf(ax(2),x,y,B); %colorbar('peer',ax(2));
  37. surf(ax(1),x,y,B-A);%colorbar('peer',ax(3));
  38. set(ax,'CLim',[cmin,cmax]);
  39. axis(ax,'xy');
  40. if plot_colorbar
  41. pos=get(ax(3),'Position');
  42. colorbar('peer',ax(3),'Position',[pos(1)+pos(3)+0.01 pos(2) 0.03 pos(4)]);
  43. end
  44. case 'scatter'
  45. switch style
  46. case 'plane'
  47. plot(ax(1),A(:),B(:),'.');
  48. delete(ax(2));
  49. delete(ax(3));
  50. unity(ax(1));
  51. end
  52. end
  53. function ax=make_axes(a,ax_w,ax_h,gap,ax_w_off,ax_h_off)
  54. if a=='h'
  55. ax(1)=axes('Position',[ax_w_off ax_h_off ax_w ax_h]);
  56. ax(2)=axes('Position',[ax_w_off+ax_w+gap ax_h_off ax_w ax_h]);
  57. ax(3)=axes('Position',[ax_w_off+2*ax_w+2*gap ax_h_off ax_w ax_h]);
  58. else
  59. ax(1)=axes('Position',[ax_w_off ax_h_off ax_w ax_h]);
  60. ax(2)=axes('Position',[ax_w_off ax_h_off+ax_h+gap ax_w ax_h]);
  61. ax(3)=axes('Position',[ax_w_off ax_h_off+2*ax_h+2*gap ax_w ax_h]);
  62. end