matlabgnuplotoctaveginput

Is there any function for getpts() of MATLAB in Octave?


I load a data file and plot it in octave. But in the plot, I want to mark the periodic appearance of points on the plot. I used ginput() function for marking. But the problem I see is, if I mark a different point which was not supposed to mark and then immediately realise that i made mistake, now I want to delete my last marked point and then mark the correct point. I'm not able to do it. I found out that there is MATLAB function getpts() which does the same but octave version of getpts() is not there. Can anyone help me out please? Example: The sequence i want to mark is 1,2,3,4,5,6,7,8,9,10. But accidently I mark 1,2,3,5 And realise that I did a mistake and then press delete button on the keyboard which deletes 5 and then I mark 4 and then 5.


Solution

  • While getpts is not implemented per se, producing a small function which gets inputs one by one via ginput and vets them to get the desired behaviour is fairly easy. E.g.

    X = []; Y = [];
    while true
      [x, y, b] = ginput(1);
      if     b == 8    ,   X(end)=[];    Y(end)=[];    % backspace key pressed
      elseif isempty(b),   break;                      % enter key pressed
      else             ,   X(end+1)=x;   Y(end+1)=y;   % any other key
      end
      disp([X;Y]);   fprintf('\n');   fflush(1);   % Optional terminal output
    end
    

    This is a very flexible approach which allows you to modify and add functionality as you desire (e.g., add different markers based on specific key pressed, plot as you go, etc).