KTFigureAxis.m 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. classdef KTFigureAxis
  2. properties (Access = public)
  3. linSpaceX = 20;
  4. linSpaceY = 20;
  5. lowerLimitX
  6. lowerLimitY
  7. upperLimitX
  8. upperLimitY
  9. axisHandle
  10. end
  11. methods (Hidden)
  12. function obj = KTFigureAxis(lowerLimitX, upperLimitX, lowerLimitY, upperLimitY, axisHandle)
  13. switch nargin
  14. case 0
  15. obj.axisHandle = gca;
  16. disp('Set the limits.');
  17. case 4
  18. obj.lowerLimitX = lowerLimitX;
  19. obj.upperLimitX = upperLimitX;
  20. obj.lowerLimitY = lowerLimitY;
  21. obj.upperLimitY = upperLimitY;
  22. obj.axisHandle = gca;
  23. case 5
  24. obj.lowerLimitX = lowerLimitX;
  25. obj.upperLimitX = upperLimitX;
  26. obj.lowerLimitY = lowerLimitY;
  27. obj.upperLimitY = upperLimitY;
  28. obj.axisHandle = axisHandle;
  29. otherwise
  30. disp('Number of input arguments is invalid.');
  31. end
  32. end
  33. end
  34. methods
  35. function obj = set.lowerLimitX(obj, limit)
  36. obj.lowerLimitX = limit;
  37. end
  38. function obj = set.upperLimitX(obj, limit)
  39. obj.upperLimitX = limit;
  40. end
  41. function obj = set.lowerLimitY(obj, limit)
  42. obj.lowerLimitY = limit;
  43. end
  44. function obj = set.upperLimitY(obj, limit)
  45. obj.upperLimitY = limit;
  46. end
  47. function obj = set.axisHandle(obj, limit)
  48. obj.axisHandle = limit;
  49. end
  50. function obj = set.linSpaceX(obj, spacing)
  51. obj.linSpaceX = spacing;
  52. end
  53. function obj = set.linSpaceY(obj, spacing)
  54. obj.linSpaceY = spacing;
  55. end
  56. function setXLabels(obj)
  57. xLim = get(gca, 'XLim');
  58. XTickMarkLocations = linspace(xLim(1), xLim(2), obj.linSpaceX);
  59. XTickMarkLabelsLocations = linspace(obj.lowerLimitX, obj.upperLimitX, obj.linSpaceX);
  60. for labelIDX = 1:obj.linSpaceX
  61. XTickMarkLabels{labelIDX} = num2str(roundn(XTickMarkLabelsLocations(labelIDX),1));
  62. end
  63. set(obj.axisHandle, ...
  64. 'XTick', XTickMarkLocations,...
  65. 'XTickLabel', XTickMarkLabels);
  66. end
  67. function setYLabels(obj)
  68. yLim = get(gca, 'YLim');
  69. YTickMarkLocations = linspace(yLim(1), yLim(2), obj.linSpaceY);
  70. YTickMarkLabelsLocations = linspace(obj.lowerLimitY, obj.upperLimitY, obj.linSpaceY);
  71. for labelIDX = 1:obj.linSpaceY
  72. YTickMarkLabels{labelIDX} = num2str(roundn(YTickMarkLabelsLocations(labelIDX),1));
  73. end
  74. set(obj.axisHandle, ...
  75. 'YTick', YTickMarkLocations,...
  76. 'YTickLabel', YTickMarkLabels);
  77. end
  78. end
  79. end