Tags: create, display, ginput, instructions, locate, matlab, newfigure, plot, point, programming, strangeness, toclick, user

ginput strangeness

On Programmer » Matlab

8,076 words with 8 Comments; publish: Tue, 06 May 2008 23:56:00 GMT; (20045.90, « »)

I am using ginput to locate a point on a plot. I create a new

figure with the plot and display instructions to the user to

click on the plot to set (x,y) or outside the plot to cancel

the operation. This works =if= the user obeys instructions.

However, sometimes a user forgets them and closes the figure

window by clicking on the x in the title bar. This causes the

GUI to hang.

Can someone please tell me what is going wrong and what I need

to do to stop the program hanging? Should I abandon ginput and

use a ButtonDownFcn callback instead?

Cheers,

Francis

All Comments

Leave a comment...

  • 8 Comments
    • Hello Francis,

      In what context are you running the code? When I run the following commands

      plot(1:10)

      A = ginput(1)

      and then close the figure window, I see the following error message:

      ? Error using ==> ginput

      Interrupted by figure deletion

      If your GUI is waiting for feedback, this may cause it to hang. You may wish

      to try calling the GINPUT function from a try/catch statement to guard

      against this situation.

      -Dan

      Dan Sternberg

      The MathWorks

      "Francis Burton" <fburton.matlab.todaysummary.com.nyx.net> wrote in message

      news:1133261121.905904.matlab.todaysummary.com.irys.nyx.net...

      >I am using ginput to locate a point on a plot. I create a new

      > figure with the plot and display instructions to the user to

      > click on the plot to set (x,y) or outside the plot to cancel

      > the operation. This works =if= the user obeys instructions.

      > However, sometimes a user forgets them and closes the figure

      > window by clicking on the x in the title bar. This causes the

      > GUI to hang.

      > Can someone please tell me what is going wrong and what I need

      > to do to stop the program hanging? Should I abandon ginput and

      > use a ButtonDownFcn callback instead?

      > Cheers,

      > Francis

      #1; Tue, 06 May 2008 23:57:00 GMT
    • Hello Daniel - Thanks for your input.

      In article <dmhtm4$cpu$1.matlab.todaysummary.com.fred.mathworks.com>,

      Daniel Sternberg <dsternbe_NOSPAM.matlab.todaysummary.com.mathworks.com> wrote:

      >In what context are you running the code? When I run the following commands

      The context is GUIDE-created GUI code, which looks like this:

      hf=figure;

      contourf(...);

      xl = xlim;

      yl = ylim;

      title('Move cursor to site and click to select (outside plot to quit)');

      done=0;

      while done==0

      [xp, yp] = ginput(1);

      if (xp<xl(1)) | (xp>xl(2)) | (yp<yl(1)) | (yp>yl(2))

      done=1;

      else

      .. do something with (xp, yp) ...

      end

      end

      delete(hf);

      >and then close the figure window, I see the following error message:

      >? Error using ==> ginput

      >Interrupted by figure deletion

      I don't see any error message, so not surprisingly enclosing the

      ginput call in a try block has no effect on the hanging behavior,

      i.e. if I click on the window close button in the title bar the

      window isn't closed and the GUI hangs until I type Ctrl-C in the

      console window.

      Francis

      #2; Tue, 06 May 2008 23:58:00 GMT
    • Daniel Sternberg wrote:

      > If your GUI is waiting for feedback, this may cause it to hang. You may wi

      sh

      > to try calling the GINPUT function from a try/catch statement to guard

      > against this situation.

      Hi Daniel,

      Sorry to harp on, but try/catch doesn't work. Is this a known issue

      with GINPUT?

      If there is a simple workaround, I will use it. If not, I'll have

      to change the design to one that uses callbacks.

      Francis

      #3; Tue, 06 May 2008 23:59:00 GMT
    • Francis,

      Sorry for the delay in responding. I didn't see your prior response. I have

      attempted to create a gui which mimics the behavior you mention and have,

      thus far, been unable to reproduce the issue. In my callback, I have the

      following code:

      try

      [xp, yp] = ginput(1);

      catch

      disp('Error caught');

      return

      end

      The code seems to execute without issue. As a consistency check, you may

      wish to run the GINPUT command from the command-line to verify whether an

      error is thrown in the simple case. As far as I know, this is not a known

      issue with the GINPUT command. If the error persists, I would recommend

      contacting our technical support staff at support.matlab.todaysummary.com.mathworks.com who can help

      to track down the issue. It is possible there is something subtle in your

      code that my simple reproductions are not catching.

      "Francis Burton" <F.L.Burton.matlab.todaysummary.com.bio.gla.ac.uk> wrote in message

      news:43945D55.79260CE4.matlab.todaysummary.com.bio.gla.ac.uk...

      > Daniel Sternberg wrote:

      > Hi Daniel,

      > Sorry to harp on, but try/catch doesn't work. Is this a known issue

      > with GINPUT?

      > If there is a simple workaround, I will use it. If not, I'll have

      > to change the design to one that uses callbacks.

      > Francis

      #4; Wed, 07 May 2008 00:00:00 GMT
    • Daniel Sternberg wrote:

      > Sorry for the delay in responding.

      No problem!

      > I didn't see your prior response. I have

      > attempted to create a gui which mimics the behavior you mention and have,

      > thus far, been unable to reproduce the issue. In my callback, I have the

      > following code:

      > try

      > [xp, yp] = ginput(1);

      > catch

      > disp('Error caught');

      > return

      > end

      Ok, I tried the code at the command prompt and it behaves as it should

      i.e. catching an error when the figure window is closed before clicking

      in the window.

      However, when I start GUIDE, put a pushbutton in the window, and paste

      the same code into the callback for the button, and then run the GUI,

      Matlab hangs until I press Ctrl-C in the command window, whereupon I

      get the following:

      Error in ==> testginput2>pushbutton1_Callback at 85

      [x, y] = ginput(1);

      Error in ==> gui_mainfcn at 75

      feval(varargin{:});

      Error in ==> testginput2 at 44

      gui_mainfcn(gui_State, varargin{:});

      ? Interrupt while evaluating uicontrol Callback.

      (Interestingly, if I paste the code to the command prompt =while= the

      GUI is running =also= hangs MATLAB, only this time Ctrl-C produces no

      message.)

      Unless someone has a sudden epiphany in the next day or two, I will

      email support as you suggest.

      Thanks for your patience.

      Francis

      #5; Wed, 07 May 2008 00:01:00 GMT
    • In article <dn1omv$q4n$1.matlab.todaysummary.com.fred.mathworks.com>,

      Daniel Sternberg <dsternbe_NOSPAM.matlab.todaysummary.com.mathworks.com> wrote:

      >issue with the GINPUT command. If the error persists, I would recommend

      >contacting our technical support staff at support.matlab.todaysummary.com.mathworks.com who can hel

      p

      >to track down the issue. It is possible there is something subtle in your

      >code that my simple reproductions are not catching.

      Quick question, as I am about to email support: can I expect

      an answer even if I have let my licence lapse? (I intend to

      reinstate it once I have found a source of funds.)

      Francis

      #6; Wed, 07 May 2008 00:02:00 GMT
    • Francis Burton:

      <SNIP does not want his/her users to inadvertently close the fig

      whilst

      one of the solutions

      - in your <ginput> module set a flag, eg, in the parent fig's

      <userdata>, while it is looping...

      - set both your figure's

      <closerequestfcn>

      -and-

      <deletefcn>

      to check for this flag...

      - the rest seems self-understood...

      just a thought

      us

      #7; Wed, 07 May 2008 00:03:00 GMT
    • In article <ef1cf25.6.matlab.todaysummary.com.webx.raydaftYaTP>, us <us.matlab.todaysummary.com.neurol.unizh.ch> wrote:

      >- in your <ginput> module set a flag, eg, in the parent fig's

      ><userdata>, while it is looping...

      >- set both your figure's

      > <closerequestfcn>

      > -and-

      > <deletefcn>

      > to check for this flag...

      >- the rest seems self-understood...

      That sounds promising. Thank you for the suggestion!

      Francis

      #8; Wed, 07 May 2008 00:04:00 GMT