Lines.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. %function lHandles = Lines(x,y,col,style,width)
  2. % plots vertical lines at x coortinated
  3. % from y(1) to y(2) , sets color col
  4. function h = Lines(varargin)
  5. ax = axis;
  6. [x, y,col,style,width] = DefaultArgs(varargin,{[],[], 'r','-',1});
  7. if size(col,1)>size(col,2)
  8. col = col';
  9. end
  10. if isempty(y)
  11. if isempty(y); y=ax(3:4); end
  12. nl= length(x);
  13. x = x(:)'; y =y(:);
  14. x = repmat(x,2,1);
  15. y = repmat(y,1,nl);
  16. h= line(x,y);
  17. elseif isempty(x)
  18. if isempty(x) x=ax(1:2); end
  19. nl= length(y);
  20. x = x(:); y =y(:)';
  21. x = repmat(x,1,nl);
  22. y = repmat(y,2,1);
  23. h= line(x,y);
  24. else
  25. if length(x)==2
  26. nl= length(y);
  27. x = x(:); y =y(:)';
  28. x = repmat(x,1,nl);
  29. y = repmat(y,2,1);
  30. h= line(x,y);
  31. else
  32. nl= length(x);
  33. x = x(:)'; y =y(:);
  34. x = repmat(x,2,1);
  35. y = repmat(y,1,nl);
  36. h= line(x,y);
  37. end
  38. end
  39. for i=1:nl
  40. if isstr(col)
  41. mycol = col;
  42. elseif iscell(col) & length(col)==nl
  43. mycol = col{i};
  44. elseif (isnumeric(col) & size(col,2)==3 & size(col,1)==nl)
  45. mycol = col(i,:);
  46. elseif (isnumeric(col) & size(col,2)==3 & size(col,1)==1)
  47. mycol = col;
  48. elseif (isnumeric(col) & size(col,2)==1 & size(col,1)==nl) | (isnumeric(col) & size(col,1)==1 & size(col,2)==nl)
  49. ColorOrder = get(gca, 'ColorOrder');
  50. mycol = ColorOrder(col,:);
  51. else
  52. mycol='k';
  53. end
  54. if isstr(style)
  55. myst = style;
  56. elseif iscell(style) & length(style)==nl
  57. myst = style{i};
  58. elseif isnumeric(style) & length(unique(style))<4
  59. stysel = {'-','--','-.',':'};
  60. [ust, dummy,ui] = unique(style);
  61. myst = stysel{ui(i)};
  62. else
  63. myst='-';
  64. end
  65. if isnumeric(width)
  66. if length(width)==nl
  67. mywid = width(i);
  68. else
  69. mywid = width;
  70. end
  71. else
  72. mywid =1;
  73. end
  74. set(h(i),'Color',mycol);
  75. set(h(i),'LineStyle',myst);
  76. set(h(i),'LineWidth',mywid);
  77. end