clickPoints2D.m 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. function [X,Y,b_success]=clickPoints2D( i_maxNoClicks, style )
  2. % function [X,Y,b_success]=clickPoints2D( i_maxNoClicks, style )
  3. %
  4. % date: 04-02-2014 (dd-mm-yyyy)
  5. % author: Alexander Freytag
  6. %% check inputs and default arguments
  7. if ( nargin < 1 )
  8. i_maxNoClicks = Inf;
  9. end
  10. if ( nargin < 2 )
  11. % default for plotting clicked points
  12. style='bx';
  13. end
  14. XY=[];
  15. keydown = 0;
  16. if ( nargout > 2 )
  17. b_success = true;
  18. end
  19. %% start clicking
  20. while ( size( XY, 1 ) < i_maxNoClicks ),
  21. % grep point from current figure by clicking
  22. p=ginput(1);
  23. % check whether input is valid
  24. if keydown==0 && ~isempty(p)
  25. % append point to point list
  26. XY = [XY; p(1),p(2)];
  27. % plot point to figure
  28. hold on ;
  29. plot(p(1),p(2),style,'MarkerSize',8,'LineWidth',1);
  30. hold off ;
  31. else
  32. % break clicking loop
  33. if ( nargout > 2 )
  34. b_success = false;
  35. end
  36. break;
  37. end;
  38. end
  39. %% final formatting of outputs
  40. if ( ~isempty( XY ) )
  41. X=XY(:,1);
  42. Y=XY(:,2);
  43. else
  44. X = [];
  45. Y = [];
  46. end
  47. end